Skip to main content
Inspiring
August 4, 2021
Answered

Data Merge Script...

  • August 4, 2021
  • 3 replies
  • 5798 views

Hi everyone,

 

I am working on a JavaScript to automate the data merge setup process. By this I mean, the script opens the Data Merge panel, executes the "Select Data Source" command, the user selects the data file, and the script draws a text frame. Where I am stuck is that I cannot figure out how to have the script populate the text frame with the fields from the Data Merge panel. Can this be done?

 

Thank you,

Jon

This topic has been closed for replies.
Correct answer Laubender

Kasyan said:

"From my experience, it’s impossible to turn on/off the preview button and switch records by script like can do in the Data Merge panel. This makes scripting Data Merge quite problematic.

— Kas"

 

Hi Kasyan,

what exactly do you mean by "switch records" ?

Do you refer to the problem that if a range of records was done and new merge should take place one cannot switch to a new range of records, because to set this one must know the maximum numbers of records in a new or updates data source?

 

One solution would be to open the source and count the lines of the records.

The other solution would be to add a new document and load the source to that document.

Then one could determine the maximum number of records with that particular source from there.

 

More details on that issue here:

 

Getting number of records in data attached to document
ashleyw42715064, Feb 24, 2020
https://community.adobe.com/t5/indesign/getting-number-of-records-in-data-attached-to-document/td-p/10943867

 

Regards,
Uwe Laubender

( ACP )

3 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
August 5, 2021

Kasyan said:

"From my experience, it’s impossible to turn on/off the preview button and switch records by script like can do in the Data Merge panel. This makes scripting Data Merge quite problematic.

— Kas"

 

Hi Kasyan,

what exactly do you mean by "switch records" ?

Do you refer to the problem that if a range of records was done and new merge should take place one cannot switch to a new range of records, because to set this one must know the maximum numbers of records in a new or updates data source?

 

One solution would be to open the source and count the lines of the records.

The other solution would be to add a new document and load the source to that document.

Then one could determine the maximum number of records with that particular source from there.

 

More details on that issue here:

 

Getting number of records in data attached to document
ashleyw42715064, Feb 24, 2020
https://community.adobe.com/t5/indesign/getting-number-of-records-in-data-attached-to-document/td-p/10943867

 

Regards,
Uwe Laubender

( ACP )

Kasyan Servetsky
Legend
August 6, 2021

Hi Uwe,

I wrote this script — to be more exact a set of scripts — a couple of years ago so I don’t remember details. The number of records wasn’t an issue because it was always static: each record corresponded to a specific language (7 in total). But the client had specific requirements for the script. Basically, it should switch to each record one by one, hide/show certain layers, and export two PDFs: one for print another for online. (7 languages x 2 PDF types x 16 pages = a lot of time to do this manually and besides InDesign often crashed during those exports).

However, record 3 — for Hungarian — was a special case: after switching to this record but before PDF export, the script should run another script that applied some formatting to prices in Hungarian forints. Theoretically, the scenario was: turn the Preview check box on and switch to the necessary record, but in practice, these two features turned out to be unavailable to scripting. So, as a workaround, I split the process into two stages:

  • for all languages except for Hungarian, it exports from Data Merge
  • for Hungarian, it exports from the document

— Kas

Community Expert
August 4, 2021

Hi Jon,

look into DOM documentation with Document and search for dataMerge:

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

 

With doc.dataMergeProperties you get to the core of DataMerge,

you e.g. load or refresh the data source with methods like:

selectDataSource() and updateDataSource()

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

 

Regards,
Uwe Laubender

( ACP )

Kasyan Servetsky
Legend
August 4, 2021

From my experience, it’s impossible to turn on/off the preview button and switch records by script like can do in the Data Merge panel. This makes scripting Data Merge quite problematic.

— Kas

Inspiring
August 4, 2021

Hi Kasyan,

 

Thank you for the reply. Currently, I have no plans to use scripting to toggle the preview button. I just want to find out if the fields in the Data Merge panel can be inserted into a text frame with a script.

 

Thanks,
Jon

Kasyan Servetsky
Legend
August 5, 2021

Hi Jon,

By script, you can do anything you can do manually in InDesign, except for the two points I mentioned in the previous post.

Here is an example: a script I made for one of my clients which creates catalogs (price lists) in 7 languages. The data -- product codes, descriptions, prices in local currencies, etc. -- is taken from a CSV file using data merge: separate record per language.

I hope it will help you to get started.

— Kas