Javascript code to take the latest date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:17 AM
Hello Community,
As a part of Data migration we are moving data from an excel sheet to serviceNow using transform map. In the excel sheet we have contact number, contract start date and end date. We made contract number as coalesce. So, For 1 contract number there are many contract start date. We have to consider only the latest start date and that corresponding end date. Can you please help me to take the latest date?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 01:29 PM - edited 05-14-2024 01:30 PM
Hi @Kavyasri,
If it's a one-off import, you can sort your spreadsheet's data in descending order by the contract start date and then import the data.
OR, you can use a Field Map script, something like the following:
answer = (function transformEntry(source) {
var sourceGDT = new GlideDateTime( source.getValue('u_opened_at')); //change it with your field name
var targetGDT = new GlideDateTime( target.getValue('opened_at')); //change it with your field name
if( sourceGDT.compareTo(targetGDT) == 1 ) //source date is after the target date
{
return sourceGDT;
}
return targetGDT; //target date is after the source, keep it
})(source);
Cheers