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.

Glide Date Time Conversion

sam352120
Kilo Guru

HI All,

Facing an error message like : (Unable to format undefined-undefined-Nov 22, using format string yyyy-MM-dd HH:mm:ss ) while loading data through transform map to the Service Now target table.

Source date time field format: Jan 17, 2019 03:18 PM   /   Target date field format: 25-03-2019 22:50:03 (Glide date time format).

I tried to achieve that through scripting in the field mapping of the transform map,But could not succeed.Let me know your inputs.

Script Use:

answer = (function transformEntry(source) {

// Add your code here
var str=source.u_shipping_date;
var strt1 = strt.split(" ");
//gs.print(strt1[0]);
var g = strt1[0].split("-");
//gs.print(g[0]);
//gs.print(g[1]+"-"+g[2]+"-"+g[0]+" "+strt1[1]);
return g[1]+"-"+g[2]+"-"+g[0]+" "+strt1[1]; // return the value to be put into the target field

})(source);

Thanks,

Sambit

 

 

1 ACCEPTED SOLUTION

This should work

answer = (function transformEntry(source) {

var date = source.u_shipping_date; // example 'Jan 17, 2019 03:18 PM';
var simpleDateFormat = 'MMM dd, yyyy hh:mm a';
var gdt = new GlideDateTime();
gdt.setDisplayValue(date,simpleDateFormat);

return gdt.getDisplayValue();
}(source);

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

12 REPLIES 12

Mihir Mohanta
Kilo Sage

Hi Sambit,

Please try the below script.

 

answer = (function transformEntry(source) {
var str = source.u_shipping_date.toString();
var gdt = new GlideDateTime();
gdt.setDisplayValue(str,"MMMM dd, yyyy K:mm a");
var dateTimeField = gdt.getDisplayValue();
return dateTimeField;
})(source);

 

Thanks,

Mihir

Hi Mihir,

Thanks for your valuable suggestion.Though the time format is acceptable by Service Now, But I am getting the below date time value populated in the computer table.

Source table date value-- Mar 21, 2019 07:37 PM   

Target Service Now value populated as 09-09-0026 10:51:00 Where as the requirement is to show the value as 

21-03-2019 19:37:00.Time format is absolutely fine ,But date format is bit erroneous.

Kindly Suggest

 

Thanks,

Sambit

This should work

answer = (function transformEntry(source) {

var date = source.u_shipping_date; // example 'Jan 17, 2019 03:18 PM';
var simpleDateFormat = 'MMM dd, yyyy hh:mm a';
var gdt = new GlideDateTime();
gdt.setDisplayValue(date,simpleDateFormat);

return gdt.getDisplayValue();
}(source);

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022