Help with script

Community Alums
Not applicable

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.Dev86_1-1727965450239.png

 

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.

 

Dev86_0-1727965364460.png

Does anyone have an idea why and can suggest a solution? Thanks

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

Did you try to debug by adding info statements?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Yes, but I am getting nothing in the logs.