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

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

 

IN RP, there is already one script written for variable set. How to use two different script then?

No, You cannot use 2 scripts there, but in the existing script you can add your lines of code at the end to set the priority - it will not do any harm as long as your script does not handling priority based on other conditions

Chaitanya ILCR
Kilo Patron

Hi @Apaul ,

1. you can use the script field in the record producer

you can access the varaible value with producer object

let say you have variable with name pvalue you can access the value with producer.pvalue

and you can compare the values and set priority with current.priority 

ChaitanyaILCR_0-1751985711486.png

 

2. you can map the variable with priority field

but make sure the variable choice value are aligned with priority field

 

example you have the choice A give it value 1 choice B value 2 etc 

to whichever value you want to map the choice to give the choice the value of priority

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya