Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Issue with the copying end date

EmeraldD
Giga Contributor

Hi all , 

 

I am trying to copy the issue end date to remediation task end date when task is creating if its end date is greater than the issue end date. I am trying with the Business rule to implement it but its not working , used before insert/update, now I am trying with the after still no luck its taking the default duration end date only ..please help me to fix this

 

 

(function executeRule(current, previous /*null when async*/) {
 
    var defaultDurationDays = 30;
 
    if (!current.start_date) {
        return;
    }
 
    var calculatedEndDate = new GlideDateTime(current.start_date);
    calculatedEndDate.addDaysUTC(defaultDurationDays);
 
    if (current.duration) {
        calculatedEndDate = new GlideDateTime(current.start_date);
        calculatedEndDate.addDays(parseInt(current.duration, 10));
    }
 
    if (current.parent) {
        var issue = current.parent.getRefRecord();
        if (issue && issue.end_date) {
            var issueEndDate = new GlideDateTime(issue.end_date);
 
            // Pick the earlier date
            if (issueEndDate.before(calculatedEndDate)) {
                current.end_date = issueEndDate.getDisplayValue();
            } else {
                current.end_date = calculatedEndDate.getDisplayValue();
            }
 
            current.update();
        }
    }
 
})(current, previous);

 

 

0 REPLIES 0