Help with script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 07:30 AM
Hi all,
I need help with this transform script:
(function runTransformScript(source, map, log, target) {
if (source.u_status == 'Failed') {
ignore = true;
return;
}
var dateStrArray = source.u_read_submission_due__t105r_.toString().split(',');
var today = new GlideDateTime();
var closestDate = new GlideDateTime('9999-12-31 23:59:59');
dateStrArray.forEach(function(dateStr) {
var excelDate = new GlideDateTime(dateStr.trim());
if (excelDate.after(today) && excelDate.before(closestDate)) {
closestDate = excelDate;
}
});
if (closestDate.before(new GlideDateTime('9999-12-31 23:59:59'))) {
target.due = closestDate.getDisplayValue();
} else {
ignore = true;
}
})(source, map, log, target);
At moment this script is updating the target.due field with future closest date to today's date, but if the target.due has already a closest date to today's, ignored the others from the spreadsheet and it keeps the existing one. Instead it should update it with closest future date to today's date from the file imported.
Example: If the source.u_read_submission_due__t105r_ in the spreadsheet has many status = open dates, it should always update the targer.due field with closest future date to todays one from the spreadsheet, so 12/11/2024.
But because the target.due has already a closest date, so 02/11/2024, the script is ignoring the 12/11/2024 which should be the correct one to be updated.
Does anyone have an idea why and can suggest a solution? Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 07:37 AM
@Community Alums
Did you try to debug by adding info statements?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 07:49 AM
Yes, but I am getting nothing in the logs.