• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

260

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

Community Expert , 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)
}	

Votes

Translate

Translate
Community Expert , 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)
}	

 

 

Votes

Translate

Translate
Community Expert ,
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)
}	

Votes

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 😉

Votes

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 Expert ,
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)
}	

 

 

Votes

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