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

date format

Participant ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

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

Views

111

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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