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

date format

Participant ,
Dec 11, 2023 Dec 11, 2023

hi
I created this code to copy the date entered in the "PURCHASE DATE" field with mm/yy format.
I inserted the formula in the calculation script of the "DATA_2" field
var s1 = this.getField("PURCHASE DATE").value;
if (s1 !== "") {var a1 = s1.replace(/\//g, '');
var b1 = util.scand("mmyy", a1);
event.value = util.printd("mm yy", b1);}
else {event.value = "";}

the console message is:
TypeError: Invalid argument type.
Util.printd:4:Console undefined:Exec
===> oDate parameter.

Please, can anyone help me find the solution?

TOPICS
JavaScript
383
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 ,
Dec 11, 2023 Dec 11, 2023

I'd have to see the test values, but util.scand() is probably returning null because the input is either ambigous or doesn't match. Why did you remove the "/"?  the slash removes ambigouity. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Dec 11, 2023 Dec 11, 2023

I found the error
the "PURCHASE DATE" field was ddmmyyyy and not mmyy
Thank you very much

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 ,
Dec 11, 2023 Dec 11, 2023
LATEST

So the input didn't match the specified format. Definately an issue, and something that could be checked with a regular expression before proceeding with the script. 

 

However, it is also a problem to not have separators in the date string. The separators make recognition of the date elements explicit. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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