Using record_id in the designer

I need to produce a unique ID for a mailing item - unique as in it cannot be repeated in a 90 day period. This then needs to be used for a mailing barcode. Although I could produce a counter in datamapper and increment (in theory although I have not tried it) the problem then is controlling that another instance create the same number.

As an alternative I thought about using the _vger_record_id in the workflow to do this but how do I access this in the designer. I see that I could create a metadata sequencer but that seems quite intensive for a value that already exists per record.

Thanks

Nigel

HA! The age-old “I need a unique number” issue…

(Not laughing at you, mind you, it’s just that this has always been a problematic issue in computing languages)

The problem with using the Record ID is that there is no guarantee it will remain unique for 90 days. It is only guaranteed to be unique when it is inserted in the database. Discarded ID’s could potentially be reused.

You could also, as you stated, create your own counter but then, you’d have to “remember” what the last counter value was so you could start from that point with every new job. And the number could never ever be reset because you need a 90-day duration on active ID’s.

One other possibility would be to use the javascript new Date().getTime().toString() method, which returns the number of milliseconds since January 1st 1970… But the problem is that your DataMapping config might be running so fast that more than one record could be processed during the same millisecond.

So what’s the solution?

Well I guess a mix of the above methods:

Create a Javascript field in the DataMapper that contains the following:

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

This code will concatenate a unique index value (the record index) with the number of seconds since 1970, so that if you have several records being processed in the same millisecond, they will each have a different starting number. And since the date/time changes with each run, you should be pretty safe as far as uniqueness goes.

Hello Phil

many thanks for your answer - it has given me food for thought.

Is there an easy way to get access to the _vger_record_id from designer though?

Cheers

Nigel

From the designer, you can use record.id. For instance, to display a customer’s first name along with the ID of the record, you could use something like:

var field, result = "";

field = record.fields["FirstName"]+" ("+record.id+") ";
if (field !== "") result += "Hello " + field + ",";

results.html(result);

Results displayed:

Hello John (1923),

Hello Phil

Thanks for looking at this again.

I think that the record id you are thinking about is the one in the designer which does in fact start from 1 each time a file is parsed. The one I am thinking about is the one in workshop which is when the meta data is created and appears to only restart when the system is re-installed - _vger_record_id. This record increments with each page - not just record and as such it is pretty much what I am looking for as a identified - currently 14873906. The alternative you suggested is really good and which we will probably use but it would be good to know how to do this above.

Thanks

Nigel

It would be good to know how to get to the _vger_record_id field

record.id gives you the internal database ID for the record (same as the _vger_record_id metadata field). Note that while in the Design tool, this value is always 0 since no record is actually persisted in the database while designing. But at runtime, it will have the proper value.

record.index gives you the index of the record within the current job.