While loading data using import set , latest date is not inserting properly in the start date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 05:04 AM
Hi Team,
we are loading a data to a a field name is Contract number it is a string field and also a a field name , is Start date t is a date /time field in the ServiceNow target table.
Data source fields like below CONTRACT_NUMBER and CONTRACT_START_DATE
As you noticed the below same contact number we have different start dates,
Requirement is, for all the same contact number latest start date is need to update.
we are mapping the CONTRACT_START_DATE to Start Date in ServiceNow target table.
written one onBefore transform script like below, to fetch the latest date and update in the Start Date field in ServiceNow target table.
But this script is not working as expected, values are inserting as it is in the excel sheet.
please guide me to correct this, or how to trouble shoot this?
Regards,
Abhilasha G T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 05:59 AM
Its not clear for me to undersand ! can you explain a bit more @Abhilasha G T
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 10:48 PM
Hi Sohail,
As you noticed in the below , we have contact number for that we have different start dates,
Requirement is, for all the same contact number latest start date is need to update.
Regards,
Abhilasha G T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 11:15 PM
i think in your script source.u_contract_start_date should be an array if you’re trying to pass it to your largestElement function. Also target.starts should be set to target.start_date (it is my perspection).
(function transformEntry(source, target, map, log, isUpdate) {
function largestElement(arr) {
var largestNum = arr[0];
for (var i = 1; i < arr.length; i++) {
if (arr[i] > largestNum) {
largestNum = arr[i];
}
}
return largestNum;
}
var startDates = source.u_contract_start_date.split(','); //id dates are comma seprated
var latestDate = largestElement(startDates);
target.u_start_date = latestDate; // Target field is set to the latest date
})(source, target, map, log, isUpdate);