Copy link to clipboard
Copied
I am trying to create a senario where everytime a user opens a master form, a number is generated sequentially in the REPORT NUMBER field.
I tried to run the script pictured below, but it's not what I need.
Brainstorming:
Can anyone advise a possible solution for this?
Thank you!
Copy link to clipboard
Copied
Looks like you copied this from an earlier post on exactly the same topic. All you need to do is change the code to match the format you want. Part of this is using actual Acrobat JavaScript functions and not making things up.
Here's a simple redo:
var oRptNumFld = this.getField("Text1");
// Divide the number into it's two parts
var aRptNumParts = oRptNumFld.valueAsString.split("-");
aRptNumParts[0] = (Number(aRptNumParts[0])+1).toString();
oRptNumFld.value = aRptNumParts.join("-");
However, this approach is problematic. As soon as a copy of the form is made the numbers will change out of sequence. Also anyone who opens the copy will see a different number than the one that it was saved with. And if they save the form, then the next person will see a different number. It's important to think these things through.
One solution would be to save two copied. One that is the working original form, and the other a flattened form for distribution.
Another solution would be to save the increment number in a global variable. So the increment can only happen on the origial system. If the form is opened on any other computer, then no increment will take place.
And yet another solution is to not put any auto-increment code in the form at all. But to use an automation script to handle all of this. The same automation script could also save the form to the correct name.
There are many other ways to do this. All of them are better than putting the auto-increment code on the document.
Copy link to clipboard
Copied
Looks like you copied this from an earlier post on exactly the same topic. All you need to do is change the code to match the format you want. Part of this is using actual Acrobat JavaScript functions and not making things up.
Here's a simple redo:
var oRptNumFld = this.getField("Text1");
// Divide the number into it's two parts
var aRptNumParts = oRptNumFld.valueAsString.split("-");
aRptNumParts[0] = (Number(aRptNumParts[0])+1).toString();
oRptNumFld.value = aRptNumParts.join("-");
However, this approach is problematic. As soon as a copy of the form is made the numbers will change out of sequence. Also anyone who opens the copy will see a different number than the one that it was saved with. And if they save the form, then the next person will see a different number. It's important to think these things through.
One solution would be to save two copied. One that is the working original form, and the other a flattened form for distribution.
Another solution would be to save the increment number in a global variable. So the increment can only happen on the origial system. If the form is opened on any other computer, then no increment will take place.
And yet another solution is to not put any auto-increment code in the form at all. But to use an automation script to handle all of this. The same automation script could also save the form to the correct name.
There are many other ways to do this. All of them are better than putting the auto-increment code on the document.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now