Auto Priority Calculation on Change Requests how to in a Business rule?

Not applicable

I really like the priority calculation client scripts on the incident table. I have also added the same client scripts to the change request form to offer the same functionality. I now want to create a business rule so that anytime the due date is changed it calculates the urgency automatically. I am then going to create a job that runs every X hours to query those change requests' due date and adjust the urgency field based on how close it is to coming due.

I have done all of the above, however I now want to recalculate the priority following the urgency field being updated by my business rule(s). The current way the priority gets updates is by a onChange client script for impact and urgency fields. They do an ajax query to bring back a "pVal" from the global business rule "calculatePriority". This value is then set in the Priority field. I cannot figure out how to have my business rule do the same thing. That is, reference the "calculatePriority" business rule and update my Priority field.

Any suggestions how I can make this possible? I would rather not duplicate the functionality, so I can keep the "calculatePriority" matrix in 1 rule. Ideas?

3 REPLIES 3

marcguy
ServiceNow Employee
ServiceNow Employee

I have a client script and a business rule doing something similar, i.e. depending on the category of change, alerting the user if they are submitting it with not much time, hopefully these scripts will help you work out what you need to do in your instance

CLIENT SCRIPT ON SUBMIT
function onSubmit() {
var type = g_form.getValue('u_change_type');
if (type == '4')
{return;
}
//Type appropriate comment here, and begin script below
var field1 = gel('change_request.u_change_status');
//See if the 'changed' attribute is true
if(field1.changed){
var status = g_form.getValue('u_change_status');
if(status == '2')
{
var start = g_form.getValue('start_date');
var category = g_form.getValue('u_category');

var script = "gs.calDateDiff(gs.nowDateTime(), '" + start + "', true);"; //uses the default calendar to find out your business hours
var dif = AJAXEvaluateSynchronously(script); //calls a function that returns the amount in milliseconds of the differernce between start date and now.
//alert(dif);
if (category == 103 && dif < 72000) //if change is minor and planned start is less then 2 business days
{
return confirm("Minor Change Lead Time Breached! - less than 2 business days before planned start, click OK to save anyway or cancel to set a new planned start time");
}
else if
(category == 102 && dif < 180000) //if change is significant and planned start is less then 5 business days
{return confirm("Significant Change Lead Time Breached! - less than 5 business days before planned start, click OK to save anyway or cancel to set a new planned start time");
}
else if (category == 101 && dif < 360000) //if change is major and planned start is less then 10 business days
{return confirm("Major Change Lead Time Breached! - less than 10 business days before planned start, click OK to save anyway or cancel to set a new planned start time");
}
}}}


marcguy
ServiceNow Employee
ServiceNow Employee

and this is the before insert or update business rule, does pretty much the same thing but marks the change as 'breached lead time' for reporting purposes (and it's easier to get a lot of the values than in the client script 🙂

/*
Module: CEN lead time check
Description: Lead times are dependent on the CategoryLead Time
Major- 10 Business Days Minor -2 Business Days Significant - 5 Business days

VersionModifiedByDescription
------- -------- ----------------------------------------------
1.0018/02/10Marc GuyCreated
*/
var start = current.start_date.getDisplayValue();
var category = current.u_category;

var dif = gs.calDateDiff(gs.nowDateTime(), start, true);
if (category == 103 && dif < 72000)
{
current.u_lead_times_breached = true;
gs.addInfoMessage("Minor Change Lead Time Breached! - less then 2 business days before planned start");
}
else if (category == 102 && dif < 180000)
{
current.u_lead_times_breached = true;
gs.addInfoMessage("Significant Change Lead Time Breached! - less then 5 business days before planned start");
}
else if (category == 101 && dif < 360000)
{
current.u_lead_times_breached = true;
gs.addInfoMessage("Major Change Lead Time Breached! - less then 10 business days before planned start");
}
else
{
current.u_lead_times_breached = false;
}


Not applicable

I appreciate your reply. What you are doing above reminds me of the risk calculator plug-in I was reading about. Creating rules to determine risk, like not enough lead time etc.
I was actually made aware of the "forcecalculatepriority" business rule which basically

current.priority = calculatePriority(current.impact, current.urgency);

I modified it just slightly to pass in the new urgency level I wanted it set to, and voila it worked great. Based on my updated due_date, the urgency field was updated, and the priority field calculated.

Thanks again, I appreciate the insight.