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

Modify DataMergeTextPlaceholder.field

Community Beginner ,
Mar 12, 2025 Mar 12, 2025

Hello, i want to modify programmatically a DataMergeTextPlaceholder changing the field with another, but the field attribute is RO. 

 

I tried to delete it to add another later using https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#DataMergeTextPlaceholders.html#... but i have errrors because the object is invalid.

var tp = doc.dataMergeTextPlaceholders[3];
var sto = tp.parentStory;
var charactersToDelete = sto.characters.itemByRange(tp.index, tp.index+tp.length-1);
charactersToDelete.remove()

 

Thanks

TOPICS
Scripting
143
Translate
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 1 Correct answer

Community Expert , Mar 13, 2025 Mar 13, 2025

Hi @giovanni_4827 ,

I looked it up. You are right. With tp.parentStory we will not get very far concerning the text of the placeholder.

However, property storyOffset should be an insertionPoint in text.

So it should be possible to access the text of a table cell with:

tp.storyOffset.parent.texts[0]

 

With tp.storyOffset you'll get an insertionPoint.

In case the insertionPoint is inside a table cell, the parent should be the table cell itself.

And texts[0] of the table cell leads you to the text

...
Translate
Community Expert ,
Mar 12, 2025 Mar 12, 2025

Hi @giovanni_4827 ,

please show your code when you try to add a new one.

Plus attach a sample InDesign test document using the forum's editor so that we can test something.

( Do not try to attach the document when answering by mail. That will not work. You have to use the forum editor. )

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Hello, i first realized the correct usage is using 

 

tp.storyOffset.index

 

 

But I'm still having the same problem. Attached a file, script and txt to reproduce the problem.

 

I'm using CS5.5. 

I think the problem is related to the table, because testing in a standard text box it works

 

Thanks

 

PS: is theren't a way to EDIT the placeHolder instead of removing and readding it?

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

It seems i can't upload the script, following the code:

#target indesign
var doc =  app.activeDocument;
var tp = doc.dataMergeTextPlaceholders[0];
var sto = tp.parentStory;
var start = tp.storyOffset.index;
var charactersToDelete = sto.characters.itemByRange(start, start+tp.length-1);
charactersToDelete.remove();
alert("OK");
Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Hi @giovanni_4827 ,

without testing anything:

Within a table cell you will not be able to use parentStory, because this is a refference to the story that holds the table and not the text inside a specific table cell.

 

What instead should work is:

var sto = tp.parent.texts[0];

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

parent is Doc and doesn't have texts

 

If I use 

var sto = tp.parentStory;
var txt =  sto.texts[0];
var start = tp.storyOffset.index;
var charactersToDelete = txt.characters.itemByRange(start, start+tp.length-1);
charactersToDelete.remove();

 

I always have invalid object

 

I have a conceptual doubt , if storyOffset.index is regarding the story in the cell (and that's right, with 2char before in the cell it says 2) if I start referencing the entire table it should count also other cells values so a bigger number. 

 

Maybe the path is right, but i'm missing the right offset.

Thanks

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Hi @giovanni_4827 ,

I looked it up. You are right. With tp.parentStory we will not get very far concerning the text of the placeholder.

However, property storyOffset should be an insertionPoint in text.

So it should be possible to access the text of a table cell with:

tp.storyOffset.parent.texts[0]

 

With tp.storyOffset you'll get an insertionPoint.

In case the insertionPoint is inside a table cell, the parent should be the table cell itself.

And texts[0] of the table cell leads you to the text of the table cell.

 

But I have to test this first.

Well, I have to work on this later.

My InDesign 2025 version 20.2 is currently crashing every time when I click the View menu…

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

 

Translate
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 ,
Mar 13, 2025 Mar 13, 2025
LATEST

Works perfectly! Thanks!

Translate
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