Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trouble setting Date/Time field with GlideDateTime in Transform Map Script

Gagana B N1
Tera Contributor

Hi all,

I’m working on a data import in ServiceNow and I’m having issues updating a Date/Time field (u_due_date) using a field script in a Transform Map. My goal is to convert a date string from the import set to a valid Date/Time value in the target table.

 

Here’s my current script in the field map:

answer = (function transformEntry(source) {
var duedate = new GlideDateTime();
duedate.setDisplayValue(source.u_due_date);
 // Set as needed (YYYY-MM-DD HH:mm:ss)
var date = duedate.setDisplayValue(source.u_due_date);
return date;
})(source);
 
Source data example:
2025-11-18 14:30:00 (as a string in the import set)
 
Issue:
The u_due_date field is not being updated after the transform runs—no errors, but the value isn’t set in the target record.
 

What I’ve checked:

  • The field is of type Date/Time.
  • The source data string matches the expected format (YYYY-MM-DD HH:mm:ss).
  • No errors in the logs.

Question:

What am I missing or doing wrong when converting and returning a GlideDateTime in a Transform Map field script? Is there a better or safer way to do this conversion so the field is reliably updated?

 

Thanks in advance for your help!

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Gagana B N1 

if the incoming value is having this format YYYY-MM-DD HH:mm:ss then no scripting required.

simply set this as Date format and it will get populated

Clear the source script and uncheck the "Use source script" field

Note: ensure there is no business rule etc which is clearing this field value

AnkurBawiskar_0-1763467938850.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader