Skip to main content
AidanCable
Participant
March 18, 2025
Question

Scripting - Insert Loaded Datamerge placeholders into text frame

  • March 18, 2025
  • 3 replies
  • 424 views

Hi everyone, 
Hoping someone here can help me. I am writing a script to automate a process that takes way too much out of my day... 

I need the data that is loaded into the datamerge window, to insert into a text frame AND link up.
At the moment I can get the text to populate based on the data, but it doesnt retain a link, can't figure out what to reference. 


Any ideas?
Thanks!




3 replies

Community Expert
March 20, 2025

Hi @AidanCable ,

there is a way to do that by ExtendScript scripting.

 

In 2018 Loic Aigon posted some code in the InDesign Scripting forum (later it that forum was merged to what you see now as InDesign User Forum ). That script, so I remember, does exactly what you want. It looked up texts like you wrote with contents <<fieldname>> where fieldname is the name of a datamerge field. Loic's script finally added datamerge text placeholders according to the field name.

 

Well, but I think that this thread is not available anymore.

At least I cannot find it…

 

As @Robert at ID-Tasker already said:

There is a method add() with object dataMergeTextPlaceholders:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DataMergeTextPlaceholders.html#d1e73552__d1e73601

 

It needs three parameters:

parentStory

storyOffset

field

 

Important notes:

In case the datamerge text placeholder should be added to text in a table text cell, be careful what you do with parameter parentStory. My guess is, that you need parent.texts[0] in case of a table text cell. And not the usual property parentStory. Had no time to do further testing…

 

BTW: storyOffset in fact is actually a insertionPoint.

The documentation I linked to is a bit misleading or hard to understand in this regards.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Colin Flashman
Community Expert
Community Expert
March 19, 2025
If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
brian_p_dts
Community Expert
Community Expert
March 18, 2025

I do not believe there is a way to insert a DM field into a frame. Your best bet is to roll ypur own DM by reading the txt or csv file using the File object and dynamically creating your document that way. 

Robert at ID-Tasker
Legend
March 20, 2025

@brian_p_dts

 

Each DataMerge Placeholders collection - has add() method.

 

brian_p_dts
Community Expert
Community Expert
March 20, 2025

I stand corrected. Must be thinking of something else. I don't oft script DM.