Highlighted

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

Community Beginner ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

My bad... The code should be:

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

TOPICS
PDF forms

Views

36.2K

Likes

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

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

Community Beginner ,
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?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

My bad... The code should be:

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

TOPICS
PDF forms

Views

36.2K

Likes

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
Jan 09, 2015 0
127 Replies 127
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Jan 09, 2015 0
Community Beginner ,
Jan 09, 2015

Copy link to clipboard

Copied

The moment the file is opened.

Likes

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
Reply
Loading...
Jan 09, 2015 0
Most Valuable Participant ,
Jan 09, 2015

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 09, 2015 0
Community Beginner ,
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.

Likes

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
Reply
Loading...
Jan 09, 2015 0
Most Valuable Participant ,
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));

Likes

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
Reply
Loading...
Jan 09, 2015 0
Community Beginner ,
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.

Likes

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
Reply
Loading...
Jan 09, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jan 09, 2015 1
Community Beginner ,
Jan 12, 2015

Copy link to clipboard

Copied

Invoice No.PNG

Likes

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
Reply
Loading...
Jan 12, 2015 0
Community Beginner ,
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

Likes

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
Reply
Loading...
Jan 12, 2015 0
Most Valuable Participant ,
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>

Likes

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
Reply
Loading...
Jan 12, 2015 0
Community Beginner ,
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.

Likes

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
Reply
Loading...
Jan 12, 2015 0
Most Valuable Participant ,
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));

Likes

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
Reply
Loading...
Jan 12, 2015 1
Community Beginner ,
Jan 12, 2015

Copy link to clipboard

Copied

THANK YOU THANK YOU THANK YOU!!!!!

I appreciate all the help!!!!!

Likes

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
Reply
Loading...
Jan 12, 2015 1
New Here ,
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?

Likes

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
Reply
Loading...
Feb 20, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 20, 2015 1
New Here ,
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

Likes

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
Reply
Loading...
Feb 20, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 20, 2015 0
New Here ,
Feb 20, 2015

Copy link to clipboard

Copied

Java.png
Am I doing something wrong?

Likes

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
Reply
Loading...
Feb 20, 2015 0
Most Valuable Participant ,
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>

Likes

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
Reply
Loading...
Feb 20, 2015 0
New Here ,
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.

Likes

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
Reply
Loading...
Feb 20, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 20, 2015 0
New Here ,
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 .

Likes

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
Reply
Loading...
Feb 23, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 23, 2015 0
New Here ,
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

Likes

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
Reply
Loading...
Feb 25, 2015 0
Most Valuable Participant ,
Feb 25, 2015

Copy link to clipboard

Copied

Can you share the file, either via a file-sharing website (dropbox, acrobat.com, etc.) or via email?

Likes

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
Reply
Loading...
Feb 25, 2015 0
New Here ,
Feb 25, 2015

Copy link to clipboard

Copied

Sure what is your email?

Likes

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
Reply
Loading...
Feb 25, 2015 0
Most Valuable Participant ,
Feb 25, 2015

Copy link to clipboard

Copied

try6767 at gmail

Likes

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
Reply
Loading...
Feb 25, 2015 0
Community Beginner ,
Apr 19, 2018

Copy link to clipboard

Copied

HI Try67

I been working on this since 2 weeks today

I am trying to create a pdf that should generate a unique requisition number
only after the user hit the submit button.

For example: User A filled the PDF form, then he hit submit button.
then the form will be sent to 3 managers, if any of the 3 managers opens
the pdf file they should see a requisition number generated automatically.

Does that makes any sense?

Likes

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
Reply
Loading...
Apr 19, 2018 1
Adobe Community Professional ,
Apr 19, 2018

Copy link to clipboard

Copied

One of the problems with creating unique numbers for a PDF is that to this you need a unique event on which to do it. If one of the scripts provided in previous posts is placed in a document script, then every time the PDF is opened it will create a new number. But what you really want is for this number to be generated once per form use. So how do you do that? Solutions provided in previous posts to this thread suggest generating the number on a submit. This is a excellent idea since the submit represents the completion of the form.

Another way to do this is to create a reset button and generate the number on form reset. Since "reset" represents the beginning of the form filling process.

The important bit here is that JavaScript can't read the user's mind to know their intention, so whether or not to generate the number. Its your form, you create the usage model, and so you have to decide what unique event is going to be used to generate the form number.

Likes

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
Reply
Loading...
Apr 19, 2018 0
New Here ,
Jan 08, 2020

Copy link to clipboard

Copied

Hi Try, 

 

I am hoping you are still contributing to the community as this thread looks older. I have created a randomly generated number in a form field and it works great; up until the point that I rest the form. After I hit the reset button on the form the field that generates a random number remains blank. How can I alter the Java to a generate the number after resetting the form? Here is the code I am using at the Document Level: 

 

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

 

Any help with this would be greatly appreciated.

 

Cheers,

 

Mark

 

 

Likes

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
Reply
Loading...
Jan 08, 2020 0
Adobe Community Professional ,
Jan 08, 2020

Copy link to clipboard

Copied

Add your script to a "Run a JavaScript" action on the reset button.

Likes

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
Reply
Loading...
Jan 08, 2020 0
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

Hello try67,

 

Can you help me with the code to have the number change only when the pdf is saved?  I have a master template for a voucher.  Each time fields are filled in and then saved, I need the voucher number to update.  In the past we have printed vouchers with sequential numbering to track the vouchers.  We're trying to move to an electronic voucher system where the form is pdf fillable and the number updates each time the voucher is saved.  

Likes

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
Reply
Loading...
Sep 28, 2020 0
New Here ,
Sep 29, 2020

Copy link to clipboard

Copied

Can you help me with the code to have the number change only when the pdf is saved?  I have a master template for a voucher.  Each time fields are filled in and then saved, I need the voucher number to update.  In the past we have printed vouchers with sequential numbering to track the vouchers.  We're trying to move to an electronic voucher system where the form is pdf fillable and the number updates each time the voucher is saved.  

Likes

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
Reply
Loading...
Sep 29, 2020 0
New Here ,
May 12, 2015

Copy link to clipboard

Copied

This is exactly what i have been trying to figure out only i want a database on a server to hand out the numbers so that multiple people in the company can access my requisition form. I can't find much help on google (perhaps i'm not searching the right words or terminology) if anyone can point me in that direction, i'd appreciate it!

Likes

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
Reply
Loading...
May 12, 2015 0
Most Valuable Participant ,
May 12, 2015

Copy link to clipboard

Copied

It's not longer possible to connect a PDF to a local DB, unfortunately. You'll need to find some other way of doing it.

I recommend using a random number instead of trying to create a sequential one.

Likes

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
Reply
Loading...
May 12, 2015 0
New Here ,
May 18, 2015

Copy link to clipboard

Copied

Hi try67,

could you help with something please?

I am using the your code to generate a new sales order number, everything working okay but my pdf has two pages page 1 the sales order page 2 T&Cs, when I switch between the tow the code changes? is there a way stopping that?

also I do not want my order number starting with 00 i just want a Radom 6 number without starting with 000

thank you

Likes

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
Reply
Loading...
May 18, 2015 0
Most Valuable Participant ,
May 18, 2015

Copy link to clipboard

Copied

What code did you use, and where did you place it?

Likes

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
Reply
Loading...
May 18, 2015 0
New Here ,
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

Likes

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
Reply
Loading...
May 18, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
May 18, 2015 0
New Here ,
May 19, 2015

Copy link to clipboard

Copied

brilliant it worked thank you

Likes

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
Reply
Loading...
May 19, 2015 0
New Here ,
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?

Likes

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
Reply
Loading...
Jun 18, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jun 18, 2015 0
New Here ,
Jun 18, 2015

Copy link to clipboard

Copied

Well that was just too easy. Thank you for your help with this!

Likes

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
Reply
Loading...
Jun 18, 2015 0
New Here ,
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?

Likes

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
Reply
Loading...
Jun 23, 2015 0
Most Valuable Participant ,
Jun 23, 2015

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jun 23, 2015 0
New Here ,
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?

Likes

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
Reply
Loading...
Jun 24, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jun 24, 2015 0
New Here ,
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...)

Likes

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
Reply
Loading...
Jun 24, 2015 0
Most Valuable Participant ,
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

Likes

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
Reply
Loading...
Jun 24, 2015 0
New Here ,
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

Likes

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
Reply
Loading...
Dec 01, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Dec 01, 2015 0
New Here ,
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

Likes

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
Reply
Loading...
Dec 01, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Dec 01, 2015 0
New Here ,
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.

Likes

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
Reply
Loading...
Dec 01, 2015 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Dec 01, 2015 0
New Here ,
Dec 01, 2015

Copy link to clipboard

Copied

The save as command

Likes

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
Reply
Loading...
Dec 01, 2015 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Dec 01, 2015 1
New Here ,
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.

Likes

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
Reply
Loading...
Dec 01, 2015 0
New Here ,
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

Likes

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
Reply
Loading...
Feb 09, 2016 0
Most Valuable Participant ,
Feb 09, 2016

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 09, 2016 0
New Here ,
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.

Likes

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
Reply
Loading...
Feb 09, 2016 0
Most Valuable Participant ,
Feb 09, 2016

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 09, 2016 1
Community Beginner ,
Feb 28, 2017

Copy link to clipboard

Copied

Thank you very much try67 you have saved me many many hours (or milliseconds).

Likes

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
Reply
Loading...
Feb 28, 2017 0