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

Data Merge Script...

Participant ,
Aug 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

3.1K

Translate

Translate

Report

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 2 Correct answers

Community Expert , Aug 04, 2021 Aug 04, 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 )

Votes

Translate

Translate
Community Expert , Aug 05, 2021 Aug 05, 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

...

Votes

Translate

Translate
Guru ,
Aug 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Participant ,
Aug 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guru ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Participant ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

Hi Kas,

I was unable to download the script using the link towards the bottom of that page 😞

All I get is a seemingly empty HTML file. I tried changing the file extension to .zip but couldn't expand it.

Jon

Votes

Translate

Translate

Report

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
New Here ,
Apr 14, 2022 Apr 14, 2022

Copy link to clipboard

Copied

Hello Kas,

is still impossible to "turn on/off the preview button and switch records" by script?

 

Thanks in advance,

Simon

Votes

Translate

Translate

Report

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
Guru ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

LATEST

Hi Simon,

quote

is still impossible to "turn on/off the preview button and switch records" by script?

As far as I know, yes, nothing has changed.

— Kas

Votes

Translate

Translate

Report

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 ,
Aug 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

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 ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

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/...

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Guru ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

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

2021-08-06_18-12-07.png

— Kas

Votes

Translate

Translate

Report

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