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.

auto populate due date based on priority

pvv1045330
Tera Contributor

Hi all,

 

I have requirement problem record like when change priority based on that due date will be populated.

If problem reported by INC is P1 -> the due date of the problem record should be +7 working days

if problem is reports by INC is P2 -> the due date of the problem record should be +12 working days
If problem is reported for a P3/P4 -> the due date should be filled in manually.

 

for this I'm using before business rule.

when to run before insert, update

condition priority is changes 

script:

var datevalue = current.priority;
var days1;
  if (datevalue == '1') {
        days1 = 14;
    } else if (datevalue == '2') {
        days1 = 2;
    } 
else if (datevalue == '3' || datevalue == '4' || datevalue == '5') {
        current.setValue('due_date','');
    }
    var ed = new GlideDateTime();
  ed.addDays(days1);
    current.due_date = ed;
})(current, previous);
 
The above script will work only priority is p1 and p2, if priority is 3 or 4 the value will cleared and getting the below error.
pvv1045330_0-1699521929622.png

 

 

 

 

1 ACCEPTED SOLUTION

Harish Bainsla
Kilo Patron
Kilo Patron

hi try this 

(function executeRule(current, previous /*null when async*/) {
var datevalue = current.priority;
var days1;

if (datevalue == '1') {
days1 = 7; // P1
} else if (datevalue == '2') {
days1 = 12; // P2
} else if (datevalue == '3' || datevalue == '4' || datevalue == '5') {
current.setValue('due_date', ''); // Clear the due date
}

if (days1) {
var ed = new GlideDateTime();
ed.addDays(days1);
current.due_date = ed;
}
})(current, previous);

View solution in original post

2 REPLIES 2

Harish Bainsla
Kilo Patron
Kilo Patron

hi try this 

(function executeRule(current, previous /*null when async*/) {
var datevalue = current.priority;
var days1;

if (datevalue == '1') {
days1 = 7; // P1
} else if (datevalue == '2') {
days1 = 12; // P2
} else if (datevalue == '3' || datevalue == '4' || datevalue == '5') {
current.setValue('due_date', ''); // Clear the due date
}

if (days1) {
var ed = new GlideDateTime();
ed.addDays(days1);
current.due_date = ed;
}
})(current, previous);

Hi Harish,

 

It's working as excepted 

Thanks for help.