Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Scripting InDesign > formFields.name in tables

Community Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Dear programmers
My script to rename formFields in InDesign unfortunately gives an error. I can apply the script and read the name of the formFields without any problem. But when I try to split it, it gives the error: "split(' ') is not a function".If the FormField is not linked to a table, everything works fine.

var myDoc = app.activeDocument;
var allformFieldsInsideTable = myDoc.stories.everyItem().tables.everyItem().formFields;
  for(var i = 0; i < allformFieldsInsideTable.length; i++){
      var ff = allformFieldsInsideTable[i];
      ff.name = ff.name.split(' ')[0];
}	

The following script works without problems.:

  var myDoc = app.activeDocument;
  var allformFields = myDoc.formFields;
  for(var i = 0; i < allformFields.length; i++){
      var ff = allformFields[i];
      ff.name = ff.name.split(' ')[0];
  }

 Thanks,

TOPICS
Scripting, SDK

Views

152

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Feb 19, 2021 Feb 19, 2021
Try this: var myDoc = app.activeDocument; var allformFieldsInsideTable = myDoc.stories.everyItem().tables.everyItem().formFields; for(var i = 0; i < allformFieldsInsideTable.length; i++){ var ff = allformFieldsInsideTable[i]; ff.name = ff.name.toString().split(' ')[0]; $.writeln(ff.name) }

Likes

Translate

Translate
Adobe Community Professional , Feb 19, 2021 Feb 19, 2021
This also works—for some reason the name is returning as a 1 item array when the form field is in a table. Split is a string function: var myDoc = app.activeDocument; var allformFieldsInsideTable = myDoc.stories.everyItem().tables.everyItem().formFields; for(var i = 0; i < allformFieldsInsideTable.length; i++){ var ff = allformFieldsInsideTable[i]; ff.name = ff.name[0].split(' ')[0]; $.writeln(ff.name) }

Likes

Translate

Translate
Adobe Community Professional ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Try this:

 

var myDoc = app.activeDocument;
var allformFieldsInsideTable = myDoc.stories.everyItem().tables.everyItem().formFields;
  for(var i = 0; i < allformFieldsInsideTable.length; i++){
      var ff = allformFieldsInsideTable[i];
      ff.name = ff.name.toString().split(' ')[0];
      $.writeln(ff.name)
}	

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Okay, that's what I call help. Thanks a lot and I don't ask further because I probably wouldn't understand 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

LATEST

This also works—for some reason the name is returning as a 1 item array when the form field is in a table. Split is a string function:

 

 

var myDoc = app.activeDocument;
var allformFieldsInsideTable = myDoc.stories.everyItem().tables.everyItem().formFields;
  for(var i = 0; i < allformFieldsInsideTable.length; i++){
      var ff = allformFieldsInsideTable[i];
      ff.name = ff.name[0].split(' ')[0];
      $.writeln(ff.name)
}	

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines