• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

How to get PDF to auto generate new invoice number everytime it is open

Guest
Jan 09, 2015 Jan 09, 2015

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?

TOPICS
PDF forms

Views

65.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 12, 2015 Jan 12, 2015

My bad... The code should be:

this.getField("Invoice No").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));

Votes

Translate

Translate
replies 138 Replies 138
Community Expert ,
Jan 09, 2015 Jan 09, 2015

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 09, 2015 Jan 09, 2015

Copy link to clipboard

Copied

The moment the file is opened.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2015 Jan 09, 2015

Copy link to clipboard

Copied

Do you want the number to remain even if the rest of the form is cleared?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 09, 2015 Jan 09, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2015 Jan 09, 2015

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));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 09, 2015 Jan 09, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2015 Jan 09, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 12, 2015 Jan 12, 2015

Copy link to clipboard

Copied

Invoice No.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 12, 2015 Jan 12, 2015

Copy link to clipboard

Copied

I have tried the above, but it is still not working...What am I doing wrong?Invoice No.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2015 Jan 12, 2015

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 12, 2015 Jan 12, 2015

Copy link to clipboard

Copied

Debugger.PNG

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2015 Jan 12, 2015

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));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 12, 2015 Jan 12, 2015

Copy link to clipboard

Copied

THANK YOU THANK YOU THANK YOU!!!!!

I appreciate all the help!!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2015 Feb 20, 2015

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2015 Feb 20, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2015 Feb 20, 2015

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?

Connecting to an External Web Site

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2015 Feb 20, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2015 Feb 20, 2015

Copy link to clipboard

Copied

Java.png
Am I doing something wrong?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2015 Feb 20, 2015

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2015 Feb 20, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2015 Feb 20, 2015

Copy link to clipboard

Copied

You need to embed it as a doc-level script for it to execute when the file is opened.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2015 Feb 23, 2015

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 .

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2015 Feb 23, 2015

Copy link to clipboard

Copied

After opening the file press Ctrl+J and check if there are any errors in the JS console.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2015 Feb 25, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines