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

Generate date and a unique number

patra
Registered: Oct 19 2006
Posts: 270

I have find from the forum a answer(Below is the script) which works fine!
The only problem I have is any time when I open the document Acrobat updates the date and the ID field.
How I will make these two fields to be locked so any time we open the form date/ID remains the same values?

Thanks

To get the current date into a field:

FormCalc:
----- form1.#pageSet[0].Page1.DateTimeField1::docReady - (FormCalc, client) ------------------------

$.rawValue = Num2Date(Date())

JavaScript:
----- form1.#subform[0].TextField1::docReady - (JavaScript, client) --------------------------------

var CurrDate = new Date();
$.rawValue = (1 + CurrDate.getMonth()) + "/" + CurrDate.getDate() + "/" + CurrDate.getFullYear();

For the ID:
JavaScript:
----- form1.#subform[0].ID[0]::docReady - (JavaScript, client) -------------------------------------

// ID field docReady JavaScript
$.rawValue = (Math.floor((new Date()) / 1000) ) %1000000000;

Last edited by gkaiseril (2008-04-19 11:44:20)

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Place these scripts in a button click event rather than in the DocReady event.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

patra
Registered: Oct 19 2006
Posts: 270
Thanks very much Thom,

There is any way to lock the button(Add #) after save as the document?

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can set the button to Read only or Hide it entirely by setting the "presense" attribute.

for a script that is attached to the button use this
this.presense = "invisible";

You could also grey out the button. See this article:

http://www.acrobatusers.com/tutorials/2007/js_disabling_fields/

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

patra
Registered: Oct 19 2006
Posts: 270
Hi Thomp,

What event I have to use for the script:
this.presense = "invisible";
for the button Add# so can be invisible after saving the form?
I have try post/pre save but doesn't work.

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Try this as a test. Put a button on a form with only this line of code in it, on the click event. When the button is clicked it should go invisible.

If that doesn't work then there is probably a syntax (or spelling) error that needs to fixed. This has to work first. Then you can go on to the next bit.

If I understand the issue correctly, you need the button, or script, to go inactive after the unique number has been set. Forcing the user to do it with a button gives the user a positive way to do it. So place both the code for generating the unique number and the code for making the button invisible in the "Click" event of the button. That way it's in one place.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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

patra
Registered: Oct 19 2006
Posts: 270
Hi Thomp,

your script now works!! THANKS
I really appreciate all your help for this matter.

One more question if I can!
How I can make the button(Add #) invisible or locked
after saving the form so next time when we open again the form
doesn,t show up the button again(We want to avoid accintetally click again the button).

THANKS
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You want to save the state of the form. Stefan Cameron, the LiveCycle Guru, has a blog on this:

http://forms.stefcameron.com/2008/09/29/restoring-the-state-of-your-form/

But if you are only talking about one button there is an easy way, make the buttons state part of the forms data.

Put an invisble check box on the form. Set it to be checked by default. When the button is made invisble, also turn off the check box.

Place code in the initailize event for the button to make is visible or invisible depending on the value of the check box.

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/]http://www.adobe.com/devnet/acrobat/[/url]

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