Change date format in field mapping using source script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2024 07:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2024 07:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2024 07:15 AM
Will It import the data with date format MM/DD/YYYY ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2024 07:18 AM - edited ‎04-23-2024 07:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2024 07:22 AM
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.