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

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

71.3K

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 139 Replies 139
New Here ,
May 18, 2015 May 18, 2015

Copy link to clipboard

Copied

hi try67,

i used code this.getField("SalesOrderNo").value =  util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));#

placed on,

page thumbnails

page 1

right click

page properties

actions

select action

run JavaScript

sorry I am new to this

thank you

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 ,
May 18, 2015 May 18, 2015

Copy link to clipboard

Copied

If you don't want the zeros at the start then use this code instead:

this.getField("SalesOrderNo").value =  Math.floor((Math.random() * 1000000) + 1);

However, this does not guarantee that the number will have 6 digits. You will need to use a loop that continuously generates new numbers if the number is too short to achieve that.

And move your code from the open action of page 1 to a doc-level script (Tools - JavaScript - Document JavaScripts) if you don't want it to run each time you scroll to that page.

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 ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

brilliant it worked thank you

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 ,
Jun 18, 2015 Jun 18, 2015

Copy link to clipboard

Copied

Hi try67! This feed has been incredibly helpful. How would I modify the script below to make it start at 00000 or 00001 (it's currently starting at 837729)

  1. var v = +this.getField("Counter").valueAsString; 
  2. this.getField("Counter").value = util.printf("%06d", (v+1));

What I'm trying to do is create a root form with auto-updating work order numbers, that can be saved as separate files, while the root form still increases with each use. If I save the root form after modifying it, then when I open it the next time, the number increases. But if I save it as a separate file, the root form number doesn't change the next time I open it. Is this possible?

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 ,
Jun 18, 2015 Jun 18, 2015

Copy link to clipboard

Copied

Just clear the value of the field (or set it to "0") and it will continue from there...

If you don't want the number to change you need to edit the file and remove the script, or flatten the form fields (but then the script will produce an error message), or define some kind of condition as to when the value needs to be incremented and when it shouldn't be.

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 ,
Jun 18, 2015 Jun 18, 2015

Copy link to clipboard

Copied

Well that was just too easy. Thank you for your help with 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
New Here ,
Jun 23, 2015 Jun 23, 2015

Copy link to clipboard

Copied

Hi there! I've got another question, this time about the pdf file, itself. Hopefully you can help? When I try to open a filled in version of this encoded form on a mobile device (iPad or iPhone, eg.), the pdf downloads with empty regions. Is there a setting I am missing when saving this file?

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 ,
Jun 23, 2015 Jun 23, 2015

Copy link to clipboard

Copied

The support for scripts on mobile devices ranges from very limited to non-existing.

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 ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

So there isn't any way to save the pdf in a "flattened" static format that is viewable on mobile devices, albeit uneditable?

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 ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

On a mobile device? I don't think so. You can flatten it in Acrobat on a regular desktop computer, though.

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 ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

Really? I've tried to "save as" the file, but it still opens as an editable form... How do I save the filled-in form as a flat, uneditable version? (I've been searching around the internet but not had any luck finding the answer to this question...)

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 ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

You can use this tool to flatten your file in Acrobat: UVSAR : Selective Flattener tool for Adobe Acrobat 8, 9 and X

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

Hey all

I am novice when it comes to adobe so hopefully someone can help me out.  Try67 already got me most of the way with his help and thank you for that but I need one last fix.  I have used this code this.getField("INVOICE").value = Number(this.getField("INVOICE").value) + 1; to make my invoice numbers go up by one every time I open it and it works great.  Now I have the problem of when I save as and rename the invoice to lets say 1001 I want that one to lock but as of now when I open 1001 it adds another number to it and changes it to 1002.  I was hoping that the original pdf will add by one but any copies will be locked down.  I have no idea how to define that.  Any help would be appreciated.

Andy

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

You need to clearly define the conditions under which the field should update, and when it shouldn't.

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

I know I need to do that but where do I do that and how is my question.  I do not have very much experience in adobe products and I am trying my best to figure things out but I am not finding much information on this other then this thread.  I am assuming that I need to add something into the document actions area but I am not sure what to write.  I would like it to save and lock the invoice 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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

How to do it is a technical question. The question I'm asking is when to do it? Should it happen each time the file is saved (probably not what you want)? Only when the file is saved under a different name? When a special button ("Save and Lock") is clicked? Something else?

You need to first describe (in words) how you want it to work, and then I could help you with the actual code to implement it.

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

Oh sorry I thought I was explaining myself.  My apologies.  So I would like the invoice number to lock when we save the file as a different name.  That would work the best.

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

Using the built-in Save As command, or using a form field button that you added to the form?

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

The save as command

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

That is complicated... I would do something different. I would put a condition on the script that populates the Invoice field so that it will only do so if the file name is something specific. For example, let's say the template file is called Template.pdf. The script would then be:

if (this.documentFileName == "Template.pdf")

    this.getField("INVOICE").value = Number(this.getField("INVOICE").value) + 1;

That's the easiest way of doing it, I think.

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 ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

That worked perfectly.  You are a pro.  Thank you for taking your time with this I appreciate it tremendously.

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 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Hey everyone, I have read all your good advices and i have trying. But, I meet some trouble with the last solution you propose.

When i reset the document (field button), i just want +1 on the old number and only there i save it.

But the result of my try is wrong, because every time I give information (name, forename, phone number …) it will provoke the script.

At the end, the result will give me +3 and not +1.

I hope i am clear in my explainations?!

Can you help me? Thanks!

Capture.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 ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Where did you place the code to populate the invoice field?

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 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

I put screenshots for a better explaination (sorry it'is in french ).

I place the code directly where my number is.

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 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Read reply #7 above. I explained there where the script needs to be placed.

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