Write a bussiness rule when incident is closed then associated problem will be closed.

S Kuanar
Tera Contributor
(function executeRule(current, previous /*null when async*/) {

    var inc = new GlideRecord('problem');
    inc.addQuery('incident',current.sys_id);
    inc.addQuery('state','!=',107);
    inc.query();
    while(inc.next()){
        inc.state=107;
        //inc.close_notes='close';
        inc.update();
    }

})(current, previous);
 
 
Why this above code didn't executed ?
7 REPLIES 7

Viraj Hudlikar
Tera Sage

Hello @S Kuanar 

 

Did you tried to debug BR ? You can add gs.log statement or utilize script tracer feature and check is your br triggered or not and what is happening? Give a more try so you will get expert in debugging issues. Also, try such script in background for one record and see if it works or not if it's good go and apply in br so it will work for all records where conditions are matched as placed by you.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Hello @S Kuanar 

 

I believe you are doing great.

Did my reply answer your question?


If my response helped, please mark it correct and close the thread so that it benefits future readers.

 

Thanks & Regards
Viraj Hudlikar

dgarad
Giga Sage

Hi @S Kuanar 

 Refer the below link

https://www.servicenow.com/community/developer-forum/when-problem-ticket-closed-then-related-inciden...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Ankur Bawiskar
Tera Patron
Tera Patron

@S Kuanar 

your script is wrong.

business rule should be after update on INC when state changes to Closed

Script as this

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

    var inc = new GlideRecord('problem');
    inc.addQuery('sys_id',current.problem_id);
    inc.addQuery('state','!=',4);
    inc.query();
    if(inc.next()){
        inc.state = 4;
        inc.update();
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader