Not yet rated
Tags:



Problem

I have an adobe form that users can download. I want any time a form is downloaded the numbers that appear on it are unique. Is there a way out?

Solution

You can create a JavaScript object to generate a GUID.

Detailed explanation

First of all, I would create a field called GUID.

Then, you can create a JavaScript object, in my example it is named "utils", in which you insert the following two functions:

//script from http://www.andrewsellick.com/92/javascript-guid-generator

function S4() {
// add a seed to randome number generator, RDF
now = new Date();
seed = now.getSeconds();
// replace 0×10000 with this format: *parseInt('10000′,16); RDF
// replace substring(1) with a 4 digit hex string like this: substring(1,5); RDF
return ((1 +Math.random(seed)) *parseInt('10000' ,16)).toString(16).substring(1 ,5);
}

 

function generateGuid(){
return (S4() +S4() +"-" +S4() +"-" +S4() +"-" +S4() +"-" +S4() +S4() +S4()).toUpperCase();
}

Then, from the form:ready event of my invisible field I would call the generateGuid() method and save the content inside the field. The "if" condition would prevent update of the Guid everytime the user reopen the form.

if (this.rawValue == "" || this.rawValue == null){
this.rawValue = utils.generateGuid();
}

 

Of course, in that way the GUID is generated not at download time, but when the user opens the form. Otherwise, you can generate the GUID server side (I think you can use the method randomUUID() of the uuid class)  and prepopulate the form with that data.

Hope this helps,

Alessio

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes