Copy link to clipboard
Copied
I am completely new to Javascript, so please bear with me!
I have an acrobat form. I would like to use Javascript to take the last two characters contained in one field on the form and join them to the current date and time, putting the result in a second field. For example: ABCD, becomes CD-24-Jan-2017-20:39
Something like this but it doesn't work, as the "WeighOrderNum" field remains blank with no ID!
var n = this.getField("RegNum").valueAsString.substr(-2);
var d = new Date(); //current date and time
var df = util.printd("-dd-mmm-yyyy-HH:MM", d)
var f = this.getField("WeighOrderNum");
f.value = n + df;
Any help is much appreciated.
Copy link to clipboard
Copied
Where did you place this code?
Are there any errors in the JS Console (Ctrl+J) when you run it?
On Sat, Mar 25, 2017 at 3:09 AM, mexicomike <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Thanks for the reply!
I placed the code in the text field properties, custom calculate script, for text field "WeighOrderNum"
The console returns "Date is not a constructor
3:Field:CalculateException in line 3 of function top_level, script Field:Calculate"
The strange thing is that the same code (to the letter) works on several other forms"
Copy link to clipboard
Copied
Something is wrong with the implementation of JavaScript on that machine.
Run a Repair Installation from the Help menu.
Copy link to clipboard
Copied
Hi,
Thanks for the input. I tried as suggested and still get the same result!
If I comment out the line "var d = new Date();"
var n = this.getField("RegNum").valueAsString.substr(-2);
//var d = new Date(); //current date and time
var df = util.printd("-dd-mmm-yyyy-HH:MM", d);
var f = this.getField("WeighOrderNum");
f.value = n + df;
Yields "CD-17-Mar-2017-00:00" if the value "ABCD" is placed in field "RegNum". So the problem appears to be with that line. All that I am missing is the time, as :-00:00" never changes.
Copy link to clipboard
Copied
Thanks for the reply!
I placed the code in the text field properties, custom calculate script, for text field "WeighOrderNum"
The console returns "Date is not a constructor
3:Field:CalculateException in line 3 of function top_level, script Field:Calculate"
The strange thing is that the same code (to the letter) works on several other forms"
Find more inspiration, events, and resources on the new Adobe Community
Explore Now