Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
My bad... The code should be:
this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
The moment the file is opened.
Copier le lien dans le Presse-papiers
Copié
Do you want the number to remain even if the rest of the form is cleared?
Copier le lien dans le Presse-papiers
Copié
I'm sorry I don't really understand. I want a new invoice number every time I open a new PDF.
Copier le lien dans le Presse-papiers
Copié
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));
Copier le lien dans le Presse-papiers
Copié
Do I put it in the Custom calculation script. Sry for all the questions I am a real newbie to this.
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
I have tried the above, but it is still not working...What am I doing wrong?
Copier le lien dans le Presse-papiers
Copié
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>
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
My bad... The code should be:
this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));
Copier le lien dans le Presse-papiers
Copié
THANK YOU THANK YOU THANK YOU!!!!!
I appreciate all the help!!!!!
Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
Any advise on what's the best method to use if I want to put it on a website similar to the link below?
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
Am I doing something wrong?
Copier le lien dans le Presse-papiers
Copié
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>
Copier le lien dans le Presse-papiers
Copié
First of all thank you so much! The number is still not changing upon open womp womp... However it works in the debugger.
Copier le lien dans le Presse-papiers
Copié
You need to embed it as a doc-level script for it to execute when the file is opened.
Copier le lien dans le Presse-papiers
Copié
Still not working; when I close the document javascript box it goes up a count but not when I open the document .
Copier le lien dans le Presse-papiers
Copié
After opening the file press Ctrl+J and check if there are any errors in the JS console.
Copier le lien dans le Presse-papiers
Copié
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
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant