Scripting - Insert Loaded Datamerge placeholders into text frame
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I stand corrected. Must be thinking of something else. I don't oft script DM.
Copy link to clipboard
Copied
Have you checked this post? I think they are trying to do the same thing:
Copy link to clipboard
Copied
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:
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 )

