These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to add 1 automaticlly

Registered: Feb 11 2010
Posts: 16

I need a number shown on a form in order for customers to trace later. That number field should be designed add 1 every time it is open. no duplicate.

Please let me know how to do it

Thank you all for helping me

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is the form opened from the same location, or on the same machine every time? Is the form only used in a local intranet?

You see, in order for every form to have a unique number, that's an incremented value, that number has to be centrally managed. There are lots of ways to do this, but how it's done depends entirely on how the form is distributed and used.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Registered: Feb 11 2010
Posts: 16
The form is used for everybody in local intranet. That individual form opens from the same location. It needs a unique number for anyone who opens that form.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is it on a network drive or a web server?

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Best option: Create a DB and assign the ID to the form using the DB connection. This is more complicated to do, however.
Other option: Create a document-level script that increments the value of your ID field when the file is opened. Problem: doesn't guarantee a unique ID because someone can copy the file locally and screw up the count.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Registered: Feb 11 2010
Posts: 16
Thank you all.

The form is an independent form located on our web server. users have to access it. It is not critical form and form life is 1 - 3 months, if users copy the file locally, it won't hurt. Can you please show me how to create a document-level script that increments the value of ID field when the file is opened.

Thank you all again for helping me. I really need your help

Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Add this to as one of the folder's java scripts:
this.getField("ID").value++;
You will obviously need to adjust the name of the field. Also, make sure you give it the value 0 in the begining.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Using the script above depends on the current value of the ID field. This value will increment only after the file has been saved. If users are opening the file from a web page, they will all get the same ID initially, and they will need to same it locally to see the increment. Of course, the different users will all get the same ID values. This is a one user solution.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Registered: Feb 11 2010
Posts: 16
So excited you can help. Thank you

I am new, only know little about document level java, never know folder's java, can you please let me know a little more?

I can tell my users to save file to get ID, If they don't do it, it will be their problem.

Thanks again for helping
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you want the ID to be unique for everyone, then you'll need to manage the ID number locally. As try67 mentioned, you could use a DB connection, but this will only work for Acrobat Professional Users, it will not work on Reader. You could write a server script to acquire the number, or you could store the value in a PDF file on a network drive. You don't need a folder level script for any of these.

Which one is suitable for your setup?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Registered: Feb 11 2010
Posts: 16
Hi, Thom

Thanks for detailed explanation and options. I showed to my boss, we like the option of store the value in a PDF file on a network drive.

Can you please let me know how?

Many many thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Create a PDF and place one form field on it. This is the ID number field.

JavaScript has the ability open a PDF file as hidden, so the user doesn't see the file. So you want to place code in the Page Open script on the first page to do exactly this. Open the ID number file, increment the number, and save the file back to the network drive. Saving this document back is where this methodology has an issue.

First I'm assuming that some users will be on Reader, so the ID number PDF will have to be Reader Enabled. Next, saving a PDF is a privileged operation. There are many different ways to handle this restriction but the easiest is to create you're own special trusted function for impleneting this operation and place it in a folder level script. Then you install this script on everyones system. So the script in the Page Open will simply call this function.

There's the technique. It's a very simple and easy way to do small inter-office data handling. The limitation is that two people cannot access the file at the same time, although this situation can be mitigated to a certain extent in code. The assumption is that the file will be opened infrequently enough that crashes will not be a problem.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

FunkyJoe
Registered: Dec 17 2008
Posts: 15
can this be done using live cycle?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes it can. I didn't outlay the entire process here. It's not a simple setup. What I didn't mention is that the operation requires a folder level trusted function. Which is required for getting info off of the hidden ID document. Then a script inside the PDF calls the folder level script to get the incremented number. For a LiveCycle form you'd use a top level envent that's only called once when the PDF is opened, such as Doc:Ready.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script