Skip to main content
Participant
March 25, 2017
Question

Unique ID using two characters from a form field plus date and time

  • March 25, 2017
  • 2 replies
  • 518 views

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.

This topic has been closed for replies.

2 replies

Participant
March 25, 2017

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"

try67
Community Expert
Community Expert
March 25, 2017

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>

Participant
March 25, 2017

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"

try67
Community Expert
Community Expert
March 25, 2017

Something is wrong with the implementation of JavaScript on that machine.

Run a Repair Installation from the Help menu.