PDFGeneratorUtils mapping Date to PDF Date Field Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 12:52 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 01:32 PM
Apparently this works as well?
var gd = new GlideDate();
var formattedDate = String(gd.getByFormat("MM/dd/yy"));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 02:40 PM
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