change priority based on variable

Apaul
Tera Contributor

Suppose there is a variable in a record producer, and it's a choice field.

 

4 choices are there: A,BCD

 

If I choose A, the priority should be changed to critical 1.

 

How to do this? Trying to do using BR but can't query the condition where I can get variable type.
IN Record Producer script I already written one script for different condition

2 ACCEPTED SOLUTIONS

YaswanthKurre
Giga Guru

Hi @Apaul ,

 

To achieve this behavior in ServiceNow, where selecting a specific value (like "A") in a choice variable on a record producer sets the priority to "Critical", you should use a Record Producer Script instead of a Business Rule.

 

 Try this in your record producer script:

// Get the value of the variable from the record producer
var selectedChoice = producer.choice_variable; // Replace 'choice_variable' with your actual variable name
// Check if the selected value is 'A'
if (selectedChoice == 'A') {
    current.priority = 1; // Set priority to Critical (1)
} // likewise do for all choices

 

  • Business Rules run on the server side, and they don’t have direct access to variables on a record producer form.
  • producer refers to the record producer variables.
  • current refers to the record being created (e.g., an Incident or Request)

 

Mark this as helpful and correct, if this helpful.

 

Thanks,

Yaswanth

 

View solution in original post

GlideFather
Tera Patron

@Apaul @J Siva @Muhammad Salar @YaswanthKurre @Chaitanya ILCR 

eeeey I just realised what we all are missing!!!

 

The Priority is calculated based on values in Urgency and Impact, so you cannot just set Priority to some value by a script, it shall be updating the two fields instead. ‼️


So the correct answer is as following:

if (your_variable == 'A'){
current.urgency = 1;
current.impact = 1;
//Priority will be caluclated: 1
}
if (your_variable == 'B'){
current.urgency = 2;
current.impact = 1;
//Priority will be caluclated: 2
}
if (your_variable == 'C'){
current.urgency = 2;
current.impact = 2;
//Priority will be caluclated: 3
}
if (your_variable == 'D'){
current.urgency = 3;
//Priority will be caluclated: 4
current.impact = 2;
}


What you have to decide is for B and D whether you want to have

  • Urg 2 / Imp 1
  • Urg 1 / Imp 2
    • both calculates the Priority as 2

Eventually:

  • Urg 3 / Imp 2
  • Urg 2 / Imp 3
    • both calculates the Priority as 4

 

Please test this solution and let me know how does this go. 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


View solution in original post

16 REPLIES 16

GlideFather
Tera Patron

Hi @Apaul,

On the Record producer you can map the variable to the field (Priority) and for the variable you can make the ABCD as labels, and its valeus to be the same as for Priority. 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@Apaul 


EDIT: this method is not applicable for Priority
Priority is calculated based on values in Urgency and Impact.


on the variable check on "Map to field" and map it to "Priority", then adjust the variable choices as following:
A - 1
B - 2
C - 3
D - 4

 

KamilT_0-1751986997313.png

 

 



On the Portal the variable will display ABCD, in the backend the Priority will be displayed accordingly because the 1234 are mapped to 1234 with corresponding labels.

KamilT_2-1751987038295.png


This will solve your issue with minimal efforts :))

EDIT: this method is not applicable for Priority
Priority is calculated based on values in Urgency and Impact.

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


GlideFather
Tera Patron

@Apaul @J Siva @Muhammad Salar @YaswanthKurre @Chaitanya ILCR 

eeeey I just realised what we all are missing!!!

 

The Priority is calculated based on values in Urgency and Impact, so you cannot just set Priority to some value by a script, it shall be updating the two fields instead. ‼️


So the correct answer is as following:

if (your_variable == 'A'){
current.urgency = 1;
current.impact = 1;
//Priority will be caluclated: 1
}
if (your_variable == 'B'){
current.urgency = 2;
current.impact = 1;
//Priority will be caluclated: 2
}
if (your_variable == 'C'){
current.urgency = 2;
current.impact = 2;
//Priority will be caluclated: 3
}
if (your_variable == 'D'){
current.urgency = 3;
//Priority will be caluclated: 4
current.impact = 2;
}


What you have to decide is for B and D whether you want to have

  • Urg 2 / Imp 1
  • Urg 1 / Imp 2
    • both calculates the Priority as 2

Eventually:

  • Urg 3 / Imp 2
  • Urg 2 / Imp 3
    • both calculates the Priority as 4

 

Please test this solution and let me know how does this go. 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@GlideFather Ahh.. 

Yep it's a blunder.

ServiceNow fundamentals 101 😂 this is like always when I tried updating the Priority in a list view and Urgency and Priority are not displayed in that list...

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */