Copy link to clipboard
Copied
I need a unique invoice number to show in the corner of a form. I was thinking of the best way (maybe the easiest?) to generate a number.. I want the form when opened to automatically create this number. In addition, one the PDF has been filled out and so on, then saved, I dont want that invoice number to regenerate once its opened again for whatever the reason. Does this sound possible?
My bad... The code should be:
this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
It's certainly possible but you need to define very well when the field should become "locked". Do you want it to happen the moment the file is saved? The moment the file is opened? Submitted? Something else?
Copy link to clipboard
Copied
The moment the file is opened.
Copy link to clipboard
Copied
Do you want the number to remain even if the rest of the form is cleared?
Copy link to clipboard
Copied
I'm sorry I don't really understand. I want a new invoice number every time I open a new PDF.
Copy link to clipboard
Copied
Then you can just use this code (adjust the field name, of course):
this.getField("Invoice") = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
Do I put it in the Custom calculation script. Sry for all the questions I am a real newbie to this.
Copy link to clipboard
Copied
Sorry, I should have explained. You need to embed it as a doc-level script, via Tools - JavaScript - Document JavaScripts.
Create a new item there, clear the default code that is generated and paste this code into the window instead.
Press OK and it should update immediately.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have tried the above, but it is still not working...What am I doing wrong?
Copy link to clipboard
Copied
What exactly is not working? Are there any error messages in the JS console
(Ctrl+J)?
On Mon, Jan 12, 2015 at 5:46 PM, JennaSanderson <forums_noreply@adobe.com>
Copy link to clipboard
Copied
When I save and reopen a invoice number does not show. This is what (Ctrl +J) shows:
Thank you for helping me figure this out.
Copy link to clipboard
Copied
My bad... The code should be:
this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copy link to clipboard
Copied
THANK YOU THANK YOU THANK YOU!!!!!
I appreciate all the help!!!!!
Copy link to clipboard
Copied
What if I wanted to make it generate a number chronologically, like 000001 and the next time it opens would be 000002, to put on a website so multiple users can click it and print it with it's unique number?
Copy link to clipboard
Copied
If the field is called Counter, for example, then you can use this code to do that:
var v = +this.getField("Counter").valueAsString;
this.getField("Counter").value = util.printf("%06d", (v+1));
However, it's not going to work correctly if you put it on a website because the value is changed on the local copy of the file that is saved on the user's machine, not on the one that's saved on the server.
Copy link to clipboard
Copied
Any advise on what's the best method to use if I want to put it on a website similar to the link below?
Copy link to clipboard
Copied
You would need a server-side application that keeps track of the number and then populates a PDF template each time a user accesses it with a copy that contains the latest one.
Copy link to clipboard
Copied
Am I doing something wrong?
Copy link to clipboard
Copied
Make sure you select the entire code when you execute it.
On Fri, Feb 20, 2015 at 6:24 PM, geraldob78294054 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
First of all thank you so much! The number is still not changing upon open womp womp... However it works in the debugger.
Copy link to clipboard
Copied
You need to embed it as a doc-level script for it to execute when the file is opened.
Copy link to clipboard
Copied
Still not working; when I close the document javascript box it goes up a count but not when I open the document .
Copy link to clipboard
Copied
After opening the file press Ctrl+J and check if there are any errors in the JS console.
Copy link to clipboard
Copied
It works perfect in the debugger and changes the number as you run the script however when I save the file and then open it in Adobe reader or Acrobat the number stays the same it never changes