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
Mega Sage

id split the source field into an array then rebuild the date...

 

something like:

var original = source.date_field;
originalArr = original.split("/");
var newDate = originalArr[2]+"/"+originalArr[0]+"/"+originalArr[1];
return newDate;

this would convert 1/2/2022 to 2022/1/2 adjust the numbers in the newArr line as needed and the seperators as well.

Will It import the data with date format MM/DD/YYYY ?

if the source value is 01/22/2024 then the array values of that would be array position 0 = 01, array position 1 = 22, array position 2 = 2024.  once you know your positions you can re-format the data in any order you want. by setting it with the separators you want to use.  originalArr[0] refers to position 0 of the array named originalArr.  if you provide the original value and the desired value i can assist further.

The original value from the source table is MM/DD/YYYY and in the same format i have to import into the servicenow.Please check on this.