Skip to main content
Inspiring
March 12, 2025
Answered

Modify DataMergeTextPlaceholder.field

  • March 12, 2025
  • 1 reply
  • 958 views

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#d1e73552__d1e73601 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

Correct answer Laubender

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


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 )

 

 

1 reply

Community Expert
March 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 )

Inspiring
March 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?

LaubenderCommunity ExpertCorrect answer
Community Expert
March 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


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 )