Change workflow should not impact while closing or cancelling change task ?

Virendra K
Kilo Sage

Hi All,

The requirement is, When I am going to Close or Cancel the Change request and if change task(s) are open then close/cancel them as well.

But the important is, Change workflow should do not impact.

 I have created After BR on Update. Please refer below script and validate it.

Specially the line related to workflow (gr.setWorkflow(false);). Will it stop to trigger Change workflow ?

 

Script:

(function executeRule(current, previous /*null when async*/ ) {
   
    var gr = new GlideRecord('change_task');
    gr.addQuery('active', true);
    gr.addQuery('change_request.sys_id', current.sys_id);
    gs.log('Vir Chg sys id ln 6 - ' + current.sys_id);
    gs.log('Vir Chg State ln 7 - ' + current.state);
    gr.query();
    while (gr.next()) {
        gs.log('Vir Tsk looped ln 10 - ' + gr.state);
        if (gr.state == 3) {
            gs.log('Vir Tsk closed PASSED ln 11 - ' + gr.state);
            gr.state = 3; // Closed Complete
            gr.active = false;
        }
        if (gr.state == 4) {
            gs.log('Vir Tsk cancelled PASSED ln 16 - ' + gr.state);
            gr.state = 7; // Closed Skipped
            gr.active = false;
        }
        gr.setWorkflow(false);
        gr.update();

    }

})(current, previous);

 

BR:

VirendraK_0-1737390180921.png

 

 

Regards,

VIrendra

 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra K 

setWorkflow(false) will stop triggering any BR or workflow paused at that stage on the record

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

View solution in original post

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Virendra K 

 

Not sure what is your business use case about no impact in change workflow? You can close/cancel the change task via wf and once you close/cancel change the change cycle will be completed.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra K 

setWorkflow(false) will stop triggering any BR or workflow paused at that stage on the record

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