Increment value for each document

Hello!

Is there a way to create increment value that will be vale of mapped field in datamapper? I need to create unique value for all print job, the way how we did that in old PP7 was by create GroupID 100000+1 for each mailpiece value was incremented. I need to do these same in Connect but don’t know what value can i use.

The way i found it work is this script:

var a = record.index+10000000;
var b = ‘’ + a;
b;

It works fine when in one pdf input there are multiple documents, but when i process many files with one document per file record.index is always 1.

BTW where can i find list of available functions that can be used in script in datamapper?

1 Like

One way to get an unique value over all print jobs may be a timestamp.

E.g. you could have a field which may get the value the JavaScript function Data.now() is returning.

The Data Mapper API is available here:

http://help.objectiflune.com/en/planetpress-connect-user-guide/1.7/#datamapper/API/Datamapper_API.htm

As for creating a unique string for each document, the approach you are suggesting doesn’t guarantee that the strings will be unique across multiple jobs. In fact there will always be duplicates.

The expression record.index+10000000; will only generate unique strings for the current job. So if you run another data file, the values will be repeated.

Are you looking to construct unique values across all jobs and never have duplicates or are you looking to reset the string at some point in time?

If you are simply after a unique string not formatted in a specific way, you could use a combination of the current time in milliseconds since 1970 and the current index number. So add an Extraction field based on JavaScript with the following expression:

var currentDate = new Date().getTime().toString();
record.index.toString()+currentDate;

This makes sure that even if Connect DataMapper is so fast that 2 or more records are created within the same millisecond, the strings are still set apart by their index within the record set; hence guaranteeing uniqueness.