Business rule script help Copy Incident Resolved state to Case state

JBbobsbobsbob
Tera Contributor

Hello , 

I am looking to edit a business rule that currently runs  when the Incident state is changed to "Resolved" the Case state changes to "Work In Progress".

I want to add an exception into the script that if the Incident state is changed to resolved  and the Case state is already  "Resolved" then the Case state does not change to "Work In Progress"

the current script in the business rule is below :

 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();
 
while(caseGr.next())
{
caseGr.close_notes = current.close_notes;
caseGr.u_symptom = current.u_symptom;
caseGr.resolution_code = current.close_code;
caseGr.u_cause = current.u_cause;
caseGr.state = 2;
caseGr.update();
}
 
})(current, previous);
 
many thanks in advance.
1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

If you are suing OOB state values in case then the below code will do the trick for you:-

 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addEncodedQuery('state!=6'); //Added this line to exclude resolved cases
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();
 
while(caseGr.next())
{
caseGr.close_notes = current.close_notes;
caseGr.u_symptom = current.u_symptom;
caseGr.resolution_code = current.close_code;
caseGr.u_cause = current.u_cause;
caseGr.state = 2;
caseGr.update();
}
 
})(current, previous);

 

Please mark my answer as correct based on Impact.

View solution in original post

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

If you are suing OOB state values in case then the below code will do the trick for you:-

 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addEncodedQuery('state!=6'); //Added this line to exclude resolved cases
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();
 
while(caseGr.next())
{
caseGr.close_notes = current.close_notes;
caseGr.u_symptom = current.u_symptom;
caseGr.resolution_code = current.close_code;
caseGr.u_cause = current.u_cause;
caseGr.state = 2;
caseGr.update();
}
 
})(current, previous);

 

Please mark my answer as correct based on Impact.

Hello,

 

If my answer helped you please mark it as correct.

 

Thanks.

JBbobsbobsbob
Tera Contributor

Thanks - works a treat.