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

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

New Here ,
Mar 24, 2017 Mar 24, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
449
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 ,
Mar 25, 2017 Mar 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>

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 ,
Mar 25, 2017 Mar 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"

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 ,
Mar 25, 2017 Mar 25, 2017

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

Run a Repair Installation from the Help menu.

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 ,
Mar 25, 2017 Mar 25, 2017
LATEST

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.

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 ,
Mar 25, 2017 Mar 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"

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