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

AUTO GENERATE AN INVOCIE # IN A SPECIFIC FORMAT

New Here ,
Sep 04, 2023 Sep 04, 2023

Hello,

I need to have my form auto-generate a number in a specific format as follows: I(or E)-23-0901-01.

-I or E: represents the document type, (Invoice or Estimate) based on a selection made in a dropdown list. (The dropdown field is named "doctype")

-23:  represents the current year (yy)

-0901: represents the current month and day (mm/dd), but without the backslash)

-01:  represents the order of creation 01, 02, 03......etc. (starting over at 01, 02, 03, etc., on the next day or date.

I'd like the # to generate upon opening a new document from a template and lock the number when it is saved and then emailed to my server. Only one person will be creating this document. Can this be done?? (The number field is named "NO"). Thanks in advance for any help given.

 

Vicki23142119gd8

TOPICS
JavaScript , PDF , PDF forms
1.1K
Translate
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 04, 2023 Sep 04, 2023

Generating the format you've specified is not a problem. There are however issues with doing this on document open, and with setting the order number. It is possible to create these features, but they would only work in Acrobat/Reader and they would not be entirely reliable.  A more robust option is to have a "Make Inoice#" button. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Sep 05, 2023 Sep 05, 2023

Hhhhhhmmkay! How do I do that?

Translate
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 06, 2023 Sep 06, 2023

Ok heres a button MouseUp script:

 

var strInvNum = "";
if(this.getField("doctype").value == "Invoice")
   strInvNum = "I-";
else
   strInvNum = "E-";

if(global.setDate != util.printd("yy-mmdd",new Date)){
     global.setDate = util.printd("yy-mmdd",new Date);
     global.OrderNum = 1;
}
else
    global.OrderNum++;

strInvNum += global.setDate + "-" + util.printf("%02d",global.OrderNum);

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 07, 2023 Sep 07, 2023

Hi,

This assumes the Acrobat application is open all day long without any crashes... Otherwise you would have to use a "counter" file or a dialog box if the global variable is not defined, to know where to resume counting!

@+

Translate
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 07, 2023 Sep 07, 2023

True, but setting the globals as persistent is a reasonable solution.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 08, 2023 Sep 08, 2023
LATEST

Hi,

So, I suggest you add a dialog box for the first opening of the file after the Acrobat application launching.

Add these lines at the begining of the script:

 

if (isNaN(global.OrderNum)) {
	global.OrderNum=app.response({
		cQuestion: "Where do you want to start numbering?",
		cTitle: "Numbering",
		cLabel: "Number #",
		cDefault: 1
	});
	global.OrderNum--;
	global.setDate = util.printd("yy-mmdd",new Date);
}

 

Please have a look on tha attached example file.

@+

Translate
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