Change date format in field mapping using source script

Hitesh Ramba
Tera Contributor

Hi I got a requirement for importing data from jdbc source where i need to import data and the date format is 02/22/2022 , but in service now field mapping there is no format present for it . I need to use Source script and make it happen so i wont get any error and the complete data will get imported to servicenow.

 

please provide the code and required solution.

 

Thanking You

8 REPLIES 8

@Jeffrey Siegel  I couldnt import the data which has date format MM/DD/YYYY .I am getting errors when running the transform map . So i need the same date format but it is not present in field mapping . So I want to use source script to get this functionality ,where i can import data into servicenow with the MM/DD/YYYY format

 

@Jeffrey Siegel  Are u available?

sorry for the delay...  what i would reccomend is using the date format yyyy-MM-dd and translate your date to that format,  the system will store it in its necessary format, the date format field is just to tell the system how to use the date you are providing....  if the original is MM/dd/yyyy, id use the following code:

answer = (function transformEntry(source) {
     var original = source.date_field;
     originalArr = original.split("/");
     var year = originalArr[2];
     var month = originalArr[0];
     var date = originalArr[1];
     var newDate = year+"-"+month+"-"+date;
     return newDate;
})(source);




Jeffrey Siegel
Mega Sage

If my answer solved your issue please accept as solution.