PDFGeneratorUtils mapping Date to PDF Date Field Issues

LeoRuggiero
Tera Contributor

Hey all, I've been having a particularly hard time mapping today's date to any PDF's date field. The format on the PDF is MM/dd/yy and I've tried a SLEW of variations to get the date to map into the PDF. I finally got it to work, but through an unconventional means. Can anyone help answer what is going on here?

 

This GlideDate script does not work, even if you .toString() the data. It will not map:

var gd = new GlideDate();
var formattedDate = gd.getByFormat("MM/dd/yy");

If you format GlideDateTime or GlideDate you get this error in the logs: "Evaluator.evaluateString() problem: java.lang.IllegalArgumentException: objectToMap: invalid type class org.mozilla.javascript.NativeJavaObject for object property Date:"

 

We've also tried getDisplayValue from GlideDate and GlideDateTime.

 

However this does work and maps just fine:

var gdt = new GlideDateTime();
var month = gdt.getMonthUTC();
var day = gdt.getDayOfMonthUTC();
var year = gdt.getYearUTC();
var yearTwoDigits = year.toString().slice(-2);
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
var formattedDate = month + '/' + day + '/' + yearTwoDigits;

 

Any ideas on what is going on here? Again I've tried so many alternatives. I've only been able to get it to work with the second script. 

2 REPLIES 2

LeoRuggiero
Tera Contributor

Apparently this works as well?

var gd = new GlideDate();
var formattedDate = String(gd.getByFormat("MM/dd/yy"));

Community Alums
Not applicable

Hi @LeoRuggiero ,

Can you please try-

var gd = new GlideDate();
var formattedDate = gd.getByFormat("MM/dd/yy").toString();
gs.print("Formatted Date : " + formattedDate);

Script execution history and recovery 


*** Script: Formatted Date : 07/11/24 

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!


Thanks & Regards,

Sanjay Kumar