Business rule

thullurishalini
Kilo Guru

How can I create a Business Rule to update incident state based on comments?

7 REPLIES 7

Bert_c1
Kilo Patron

You can look at OOB business rules in your instance, to start.  Read:

 

https://docs.servicenow.com/bundle/xanadu-api-reference/page/script/business-rules/concept/c_Busines...

 

Create a new BR to run for 'Insert' and 'Update', set When to 'Before'. and use Conditions to set the incident_state as desired. If a condition like "Comments", "Contains", "some value" won't work, then use javascript to contain the logic.

Manikanta Kota
Mega Guru

Hi @thullurishalini ,

Please Reuse This script Business rule

(function executeRule(current, previous /*null when async*/) {

if (current.comments.changes()) {

current.state = 2; // Example: Set state to 'In Progress'
}
})(current, previous);

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

 

Regards,

Manikanta. Kota

Sai Krishna6147
Mega Guru

Hi @thullurishalini 

It may helps to you follow the steps:

1.Go to Application Navigator

All>System Definition>Bussiness Rule

and click on business rule 

2. After List view opened ,Click on New

3. After the clicking on New Tab, configure the details like name etc according to requirement

4. Give Table : incident

5. In when to run

Apply the condition filter

Comments changes

Enable Update select box

6. Apply in action Tab the following filter condition:

state  changes to In progress/on hold/resolved

7. Save it and Run.

Refer: https://docs.servicenow.com/bundle/xanadu-api-reference/page/script/business-rules/concept/c_Busines... 

Thank you, please make helpful if you accept the solution.

Sandeep Rajput
Tera Patron
Tera Patron

@thullurishalini What exactly your requirement here? If you are updating incident state based on the comment added by the user then there is something wrong with your approach here. Ideally, incident state should not be updated based on comment. 

 

In case if you still want to persue this idea then you can plan to create an onBefore update business rule which changes state of the incident whenever the comment field changes.