Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

update state of incidents pending change when change is implemented

Teresa Ruiz
Tera Contributor

Hi,

 

How can i make a business rule to change incident state of incidents pending change when this change is implemented?

 

all help is welcomed 🙂

1 ACCEPTED SOLUTION

Apeksha Joshi
Kilo Guru

Hi Teresa ,

try this script :

write an after insert / update business rule on incident table 

var gr = new GlideRecord('change_request');

gr.addquery('parent',current.sys_id);

gr.addquery('state',7);

gr.query();

if(gr.next())

{

current.setValue('incident_state',6);

current.update();

}

 

Mark my answer correct and helpful based on impact.

Regards,

Apeksha

 

View solution in original post

5 REPLIES 5

Geetanjali Khy2
Mega Guru

Hi Teresa,

Please refer below link, it may help you.

https://community.servicenow.com/community?id=community_question&sys_id=2425876ddbd8dbc01dcaf3231f96...

 

Kindly mark the answer as Correct and Helpful if this answers your question.

Thank You.

 

Regards,

Geetanjali Khyale

Namrata Khabale
Giga Guru

Hey Teresa,

 

Try in this way:

 

Business rule name: Resolve incidents from implemented change
Execute after update
Table: change_request
Condition: current.state.changesTo(3) // state 3 is closed complete, by default
Script: Query for all incidents that are pending change related to this change, and resolve them with some default comments



var gr = new GlideRecord("incident");
gr.addQuery("rfc", current.sys_id);
gr.addQuery("state", 4); // incident state 4 is pending change
gr.query();
while (gr.next()) {
// resolve the incident
gr.state = 6; // OOB, resolved is 6
// add some canned comments to the resolved incident
gr.comments = "This incident has been resolved due to the successful implementation of change request " + current.number;
// don't forget to actually update the incident!
gr.update();
}

Hit the Correct and Helpful if works.

Thanks
Namrata.

Thanks a lot for your reply!

Apeksha Joshi
Kilo Guru

Hi Teresa ,

try this script :

write an after insert / update business rule on incident table 

var gr = new GlideRecord('change_request');

gr.addquery('parent',current.sys_id);

gr.addquery('state',7);

gr.query();

if(gr.next())

{

current.setValue('incident_state',6);

current.update();

}

 

Mark my answer correct and helpful based on impact.

Regards,

Apeksha