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

IK I can use record prod script but there is already one script running. how can i use two different script>

Hi @Apaul You don't need to use different script you can just set value of priority in same script.

OR

Just map the choice variable with priority with same choice labels but set values of choice as in priority like Label A value 1 etc.

@Apaul Please share the existing script. If the current script does not assign a priority value, you may append additional lines to update the priority accordingly.

@J Siva and is a script necessary? the variable choices can be mapped to the priority choices and ServiceNow does the trick without any overkill, no?

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


Muhammad Salar
Giga Sage

Hi @Apaul 
Set priority in record producer script on condition
For example:

if (choice == 'A'){
current.priority = 1;
}
if (choice == 'B'){
current.priority = 2;
}