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

Getting number of records in data attached to document

Explorer ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

Hi

Could anyone tell me how to get the number of records in the data attached to a document?

I've been trying to write a script which needs this to work. I've been looking through the data model at DataMerge options and preferences but I can't seem to find anything that stores the data count.

Thanks!

TOPICS
Scripting

Views

943

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 ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

doc.dataMergeProperties.dataMergePreferences.recordNumber;

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hmm - that just reads 1, so it's just the record I'm on at the moment?

I tried going to the last record before running the script and it still came out as 1.

Do I need to do something else?

I'm using var doc = app.activeDocument;

Cheers

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi Ashley,

see into other properties of dataMergePreferences as well:

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

 

Set recordSelection to RecordSelection.RANGE

And exploit property recordRange that returns a string.

 

var doc = app.documents[0];
doc.dataMergeProperties.dataMergePreferences.recordSelection = RecordSelection.RANGE;
var rangeString = doc.dataMergeProperties.dataMergePreferences.recordRange;
var lastNumberString = rangeString.split("-")[1];
var lastNumberAsInteger = parseInt( lastNumberString , 10 );

alert( lastNumberAsInteger );

 

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi

 

That looks promising, but currently returns 500 instead of the actual 1500 records - that's because the last time I exported I only selected records 1-500.

I guess it should be possible to tweak this to get all the records all the time - I'll have a look!

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi Brian,

property recordNumber is something else. From my German InDesign on Windows 10:

 

DataMerge-UI-Merge-1.PNG

 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi Ashley,

then I suggest you set recordSelection first to RecordSelection.ALL_RECORDS.

Did not test this, but I hope that the range will adapt.

 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hm…

If this does not help you may load the data source again.

 

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi

 

Unfortunately it 'remembers' the previous range, so I'd need some way to change the range to specify the full range of records (and I guess if I could do that I would already have the total number of records!)

 

I'll tinker with it some more.

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Yes. It's a bug. I usually create a variable for the total amount of records by doing a line-count of data within the text file being referenced.

csvFile.open('r'); 
var maxRange = csvFile.read().split(/\n/).length - 1;  //total length of actual records (not including the header)
csvFile.close(); 

 

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi Colin


EDIT - Just tried it and I'm getting a 'csvFile is undefined' message. I can set up the var, but how do I tell it to look at the current data source?

 

Thanks

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

You need to define and open the CSV file first. 

 

var csvFile = File("path/to/file/thedata.csv");

 

For example, if the file is on your desktop and called data.csv, then you would do: 

 

var csvFile = "~/Desktop/data.csv";

csvFile.open('r');

...

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 ,
Nov 27, 2024 Nov 27, 2024

Copy link to clipboard

Copied

Hello, old post but i'm in the same situation, i need to get the total of reccords. But i don't want to upload a news db file, i would like to get the one is in link. it's a txt can you help me ?

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 ,
Nov 27, 2024 Nov 27, 2024

Copy link to clipboard

Copied

Hi @Morgane33604108ep9w ,

see into this workaround:

Load the data source to a new document and get the range from there.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

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 ,
Nov 27, 2024 Nov 27, 2024

Copy link to clipboard

Copied

LATEST

Thank i find an other solution 🙂 i find the right file by a research of the txt or csv file in the links 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Hi Colin,

the other workaround:

Load the data source to a new document and get the range from there.

 

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 ,
Feb 26, 2020 Feb 26, 2020

Copy link to clipboard

Copied

Hi Ashley,

it seems you cannot reply to this thread for unknown reason:

https://community.adobe.com/t5/indesign/cannot-reply-to-post/td-p/10947947

 

So I am trying a reply to see if something's wrong on the thread in the forum.

 

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 ,
Feb 26, 2020 Feb 26, 2020

Copy link to clipboard

Copied

Just answered in the other thread, but I'll repeat it here.

 

Question was:
How can I know the data source file of a document template that is prepared for data merge?

It seems there is no property in the scripting DOM for this. I'd expect this perhaps with documentPreferences or dataMergePreferences. But no, it's missing.

 

The solution:

Export your document to IDML and look into Preferences.xml of the IDML container.

In the third line you should find the DataSourceFile attribute:

<DataMerge DataSourceFile="C:\folderName\fileName.txt" />

 

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