Business Rule not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi,
I am trying to create a Business Rule for the incident matrix. Priority is not getting changed. Kindly help.
(function executeRule(current, previous /*null when async*/) {
var imp = current.u_impact.getValue();
var urg = current.u_urgency.getValue();
//var pri = current.u_priority;
gs.info('impact is ' + imp + ' urgency is ' + urg);
if((imp == '1') && (urg == '1')){
current.u_priority = '1';
}
else if((imp =='1') && (urg == '2')){
current.u_priority = '2';
}
else if((imp == '1') && (urg == '3')){
current.u_priority = '3';
}
else if((imp == '2') && (urg == '1')){
current.u_priority= '2';
}
else if((imp == '2') && (urg == '2')){
current.u_priority='3';
}
else if((imp == '2') && (urg == '3')){
current.u_priority='4';
}
else if((imp == '3') && (urg == '1')){
current.u_priority='3';
}
else if((imp == '3') && (urg == '2')){
current.u_priority = '4';
}
else if((imp == '3') && (urg == '3')){
current.u_priority = '5';
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ServiceNow Use6 ,
getValue() returns a string (e.g., "1", not 1). If you want to compare with numbers, use parseInt().
Also, to update a field in a Business Rule, use current.setValue() instead of direct assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If impact and urgency are integer, no need to use quotes. If they are string, use quotes.
Check your if else condition and change the condition value accordingly and it should work.
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Refer below knowledge article for more details,
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0725069
As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ServiceNow Use6 ,
are you talking about Incident(incident) table?
if yes
check if there is any Priority look rules are active or not if you are using the priority look up rules
you can go to the matcher table and adjust record (OOB matcher table for incident is dl_u_priority)
Better use the priority lookup
if you are using the BR to set the value the impact field name is (impact) not u)impact and urgency (urgency) not and urgency and priority is priority not (u_priority)
if this BR is on different table and field names are correct
you can update the BR script as below
(function executeRule(current, previous /*null when async*/ ) {
var imp = current.getValue('u_impact');
var urg = current.getValue('u_urgency');
//var pri = current.u_priority;
gs.info('impact is ' + imp + ' urgency is ' + urg);
if ((imp == '1') && (urg == '1')) {
current.u_priority = '1';
} else if ((imp == 1) && (urg == 2)) {
current.u_priority = '2';
} else if ((imp == 1) && (urg == 3)) {
current.u_priority = '3';
} else if ((imp == 2) && (urg == 1)) {
current.u_priority = '2';
} else if ((imp == 2) && (urg == 2)) {
current.u_priority = 3;
} else if ((imp == 2) && (urg == 3)) {
current.u_priority = 4;
} else if ((imp == 3) && (urg == 1)) {
current.u_priority = 3;
} else if ((imp == 3) && (urg == 2)) {
current.u_priority = 4;
} else if ((imp == 3) && (urg == 3)) {
current.u_priority = 5;
}
})(current, previous);
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya