PDF auto numbering for Invoices

Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

I need to add unique invoice number to a form that will auto-populate the new number every time the form is saved. The number needs to be 2022-IN-20000 with the new number following as 2022-IN-20001 and so forth. Can anyone help? Thanks

TOPICS
PDF forms

Views

76

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
community guidelines

correct answers 1 Correct answer

Community Beginner , Sep 20, 2022 Sep 20, 2022

I am noticing one problem if you can help. When I add my digital signature to the document and save it and then reopen the saved document later it advances the saved number to the next number. Saving the document after signing marks all fields as read only and I cant change the number back. Is there a way to lock that number once it is saved so that it wont advance when I reopen it later. 

Likes

Translate

Translate
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

Will there be only one copy of this file? If not, you will get duplicates values, as one copy can't know which numbers have been used by the other.

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
community guidelines
Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

There will only be one copy for each number. I am a Justice of the Peace and this is a form that I open and fill out each time I conduct an Inquest and each form has to have a separate case number that runs in order. After I fill the form out, I save it to a file on my computer. The number needs to start with 2022-IN-20000 and advance to the next number each time the document is saved. 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
community guidelines
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

OK, then create a (read-only) text field in the location where you want this number to appear and call it "InvoiceNumber". Then go to Tools - JavaScript - Set Document Actions and place the following code under the Will Save action:

 

var f = this.getField("InvoiceNumber");
var s = f.valueAsString;
if (s=="") f.value = "2022-IN-20000";
else {
	var parts = s.split("-");
	var currentNumber = Number(parts[2]);
	f.value = "2022-IN-"+(currentNumber+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
community guidelines
Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

I did as you said but each time I open a new document the number reset back to 2022-IN-20000 instead of advancing to the next 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
community guidelines
Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

It will only advance to 2022-IN-20001 and then start over when I open the new document. I need the original form to remember the last saved 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
community guidelines
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

You have to save the file when closing it for the number to update, as you've requested.

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
community guidelines
Community Beginner ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Thank you very much for your help. I have one last request of you if you will. Can you change this code so that the number will advance when the document is opened instead of when it is saved? 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
community guidelines
Community Expert ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

To do that move it to a script under Tools - JavaScript - Document JavaScripts, but NOT in a function.

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
community guidelines
Community Beginner ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

This works perfectly. Thank so much for your help and have a great week. 

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
community guidelines
Community Beginner ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

LATEST

I am noticing one problem if you can help. When I add my digital signature to the document and save it and then reopen the saved document later it advances the saved number to the next number. Saving the document after signing marks all fields as read only and I cant change the number back. Is there a way to lock that number once it is saved so that it wont advance when I reopen it later. 

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
community guidelines