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

Automatic Number Generation When Opening an Acrobat Form

Community Beginner ,
Jun 22, 2010 Jun 22, 2010

Hello,

I've created a PDF Job Ticket Form with several input fields using Acrobat Pro, now I would like to have this form automatically generate a sequencial number on each page of the form everytime it opens. This number would serve as a Job Number or an Invoice Number so it would need to be unique everytime it was generated.

I would assume this would be a simple script that could grab the previous job number and increase the value by one, but I'm am unsure how/where to save the previous job number in the form so that the number/field can be incremented sequencially each time it opens?

If this is possible I would greatly appreciate any help you can provide.

Thanks in advance!

28.2K
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
LEGEND ,
Jun 22, 2010 Jun 22, 2010

There are a number of facts that need to be known.

Will more than one person be using this form at one time?

Will any users be using Reader?

Will the form be saved after each use?

Will all users be on a WAN?

Will this form be accessed through the Internet?

See Acumen Journal August 2004 for an article about the Acrobat global object that will work with Acrobat and Reader and does not require using a database.

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 Beginner ,
Jun 22, 2010 Jun 22, 2010

Ok no problem...

Will more than one person be using this form at one time?

Yes it will be used by roughly 2-3 people with a copies of the original form, but if need be I can always give each user a number series to keep the Job numbers unique. Ex. User 1 = 1000xxxx  User 2 = 2000xxxx etc...

Will any users be using Reader?

Yes it would be ideal if this could be done in Reader.

Will the form be saved after each use?

Probably not, but if thats helpful in the solution it can be done.

Will all users be on a WAN?

I can't think of any reason for it.

Will this form be accessed through the Internet?

No, it will input directly on each individuals computer.

Thanks for the help.

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 Beginner ,
Jun 25, 2010 Jun 25, 2010

Ok I've reviewed the document you posted in the first link (great tutorial by the way) and I think I'm pretty close to getting this to work. Just have a few last min questions.

This is the code I've come up with for the open counter.

if (global.count == null) {
global.count = 1000000
global.setPersistent("count",true)
}
else
global.count++
var f = this.getField("jobCount")
f.value = global.count

The code works and executes to update the correct field. What I don't know is if I placed in the right place. I chose to put it in the actual form fields custom calculation box (I'm very new to javascript and scripting in general so please forgive me). I'm assuming this is why the code doesn't automatically execute when I re-open the pdf. So my next question is where exactly should I place this code? The tutorial said there is a document javascript location, but it wasn't in the menu options they described in my version of acrobat (9) and I'm assuming the location has moved with the updates to Acrobat since the tutorial was written.

My second question now that I have the code working correctly, is this something that will only work in Acrobat or can it be executed in Reader as well?

Thanks for the help!

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 Beginner ,
Jul 01, 2010 Jul 01, 2010

Ok after a few days I feel like a bit of a moron, but I'll try and plead that I'm still new to forms and javascript in general.

I have found a solution that works pretty well so I thought I share and hopefully it can help someone else in the future.

I placed this block of code in the document javascript file (Advanced>Document Processing>Document Javascripts...)

if (global.count == null) //checks to see if count exists

{
global.count = 1000000 //sets initial count, you can change to suite your needs
global.setPersistent("count",true) //makes the counter a global object so it is persistent data
}
else
global.count++ //increments the the counter by one when the document is opened
var f = this.getField("jobCount") //creates a variable for the form field where the counter will be displayed
f.value = global.count //sets the form field to equal the counter

This increments the global variable each time I open the document. I also decided I might need a reset button so the I just added a basic button and added this script to the button mouse up action.

if (global.count != null) {
global.count = 1000000
global.setPersistent("count",true)
}
else
global.count = 1000000
var f = this.getField("jobCount")
f.value = global.count

Probably doesn't need to be in an if statement, but I did it anyway.

I got most of my code from this article (thanks for referring it GKaiseril) so if you need any further explanation it does a wonderful job of explain what each portion of the code does and how/why you need a global variable.

August 2004
Issue 34

http://www.acumentraining.com/acumenjournal.html

Hope this helps someone else.

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 ,
Jul 22, 2010 Jul 22, 2010

Hi great script, only pitty it dont work on our SBS2008 server, with mac and pc computers, we get the error in javascript debugger: NotAllowedError, security settings prevent to acces, this even with document on the server or local pc

Schermafbeelding 2010-07-22 om 16.43.40.png

but there are no security items in our form.

Has someone else the same problem? Or solution? Or need i have a special plugin for this?

Thanks, Theo

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
LEGEND ,
Jul 24, 2010 Jul 24, 2010

It is a restriction set by Acrobat, You may need to adjust your and all user's Acrobat preferences to allow 'Enable global object security policy'.

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 ,
Jul 30, 2010 Jul 30, 2010

This is not the solution, pitty.

We work with Acrobat 9 Pro, Reader, Acrobat 6

Does anyone can help me?

Theo

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 ,
Aug 04, 2010 Aug 04, 2010

These are my setting in Acrobat, but still got the same error of security settings, what are the right settings?

Schermafbeelding 2010-08-04 om 11.12.23.pngSchermafbeelding 2010-08-04 om 11.12.39.png

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 Beginner ,
Aug 06, 2010 Aug 06, 2010

Those appear to be the same settings I used. Not sure why you would be getting that error still.

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 ,
Aug 08, 2010 Aug 08, 2010

Its strange but when i disable the settings, its works! but on every computer i get a different number, example on one computer i get starting the numbering at 1, on a other i get the right number starting with 700 and that is what i want, on a other computer it starts with 62, maybe i need a other script, if someone can help me with that, i will be very grateful

Theo

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 ,
Jun 22, 2017 Jun 22, 2017

I am trying to do a similar script and having issues.  Below is a script in the document section of the javascripts and the field name/format

What am I doing wrong?  Nothing displays.

 

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 ,
Jun 22, 2017 Jun 22, 2017

Save, close and then re-open the 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
New Here ,
Jun 22, 2017 Jun 22, 2017

I did and the field is still blank

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 ,
Jun 22, 2017 Jun 22, 2017

Go to Edit - Preferences - JavaScript and make sure that the "Enable global

object security policy" box is NOT ticked.

On Thu, Jun 22, 2017 at 6:06 PM, pamc90562799 <forums_noreply@adobe.com>

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 ,
Jun 22, 2017 Jun 22, 2017

That was it!!!  Your awesome!  Thanks

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 ,
Apr 05, 2019 Apr 05, 2019

I know this is sort of an old post, but it is the only one I've found.

Thanks for the info on this as I really need to do this for two forms we have.  I used your script as you posted it and I have it working on the first form.  I did have to make one change as the counter would increase by 2 instead of one.  I changed global.count++ to global.count +1.  After that it worked great.

My problem lies with the second form.  I have tried applying the script the same way on the second form, but it doesn't seem to work right.  It doesn't want to increment each time when it is opened.  Also, if I go and open form 1 after opening form 2, it reuses the number that form 2 had instead of incrementing by 1.

I want both of these forms to use the same global counter.  Regardless of which form is opened, I want it to take on the next number.

These forms will be used on a single computer.

I am very new to javascript and would appreciate any help.  Do I not want the entire script on form 2 or am I doing something else wrong?

Thanks in advance!

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 ,
Apr 06, 2019 Apr 06, 2019

The difference between global.count++ and global.count+1 is that the former actually changes the value of the variable. The latter one doesn't. If you want to add two instead of one then use global.count+=2.

And the reason you're getting cross values is that you're only using a single variable, and it's global. So you should use two separate ones, something like global.count1 and global.count2, and this problem will be solved.

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 ,
Apr 06, 2019 Apr 06, 2019

Thank you so much for your response.  I did change them to have separate variables and and for whatever reason the increment is working now with the ++.  Each form now seems to work separately, but what I want is for them to work as one.  I want it to increment to the next number regardless if they open form1 or form 2.  Hope that makes sense.  What would I have to change on the script for the second form for it to use the same counter?   This is the script that I have on form1.

if (global.count1 == null) //checks to see if count exists 

global.count1 = 10000 //sets initial count, change to suit your needs 

global.setPersistent("count1",true) //makes the counter a global object so it is persistent data 

else 

global.count1++ //increments the counter by one when the document is opened 

var f = this.getField("PVFCount") //creates a variable for the form field where the counter will be displayed 

f.value = global.count1 //sets the form field to equal the counter

Thanks for helping me with this.

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 ,
Apr 07, 2019 Apr 07, 2019

In that case go back to using a single variable...

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 ,
Apr 07, 2019 Apr 07, 2019

It isn't working for me.  Do I need to adjust the script on the second form?  It seems to repeat the same number when switching from form2 to form1.  Form2 doesn't increment sometimes either.  Appreciate your help.

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 ,
Apr 07, 2019 Apr 07, 2019

Post the code you're using in both files.

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 ,
Apr 07, 2019 Apr 07, 2019

I used the same code in both and then tried it with just having the counter increase (section after the else).  It was close to working so I'm sure I just need the code adjusted slightly.

if (global.count == null) //checks to see if count exists

{

global.count = 10000 //sets initial count, change to suit your needs

global.setPersistent("count",true) //makes the counter a global object so it is persistent data

}

else

global.count++ //increments the counter by one when the document is opened

var f = this.getField("PVFCount") //creates a variable for the form field where the counter will be displayed

f.value = global.count //sets the form field to equal the counter

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 ,
Apr 07, 2019 Apr 07, 2019

Seems fine to me. What exactly goes wrong with it?

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 ,
Apr 07, 2019 Apr 07, 2019

It was using the same number instead of incrementing when going from Form2 to Form1.  Sometimes Form2 would not increment at all.  Strangely enough, it seems to be working right now.  I had changed the forms to use separate counters as you had suggested (count1 and count2) and they worked individually like there should have.  Now for whatever reason, when I put them back to using the same counter, it seems to be working.  Not sure why or how, but I'm happy it is working.  I will try it again tomorrow to make sure that it continues to work consistently.

Thanks for your help.  Changing the counter name seems to have reset something.

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