When a change request is cancelled "Pending" change tasks have to be put on state "Cancelled"

Tuhina Sharma
Tera Contributor

I have a requirement When a change request is cancelled all pending change tasks have to be put on state "cancelled" as well. Currently they remain on "pending"

 

I tried this script in the workflow

TuhinaSharma_0-1687333802012.png

And add this here

TuhinaSharma_1-1687333898315.png

 

But it is not working and I also tried UI policy, scripts but it is not reflecting on change task, please send any suggestions on how to accomplish this.

 

4 REPLIES 4

Peter Bodelier
Giga Sage

I guess this workflow is running on the change_request table?

If so, you'll have to lookup the tasks before you can close them. You are currently only updating the state of the change itself.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Yes this workflow is running on the change_request table.

But what will be the solution I also updated the change_task table, tried UI Policy, scripting but nothing works.

Sandeep Rajput
Tera Patron
Tera Patron

@Tuhina Sharma Create following business rule on Change Request table.

 

Screenshot 2023-06-21 at 4.44.00 PM.png

Screenshot 2023-06-21 at 4.46.10 PM.png

 

Here is the script for the BR.

 

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

    // Add your code here
    var gr = new GlideRecord('change_task');
    gr.addQuery('change_request', current.sys_id);
	gr.addQuery('state','-5');//Pending state filter
    gr.query();
    if (gr.next()) {

        gr.setValue('state','4');//Set to cancelled        
        gr.update();
    }
})(current, previous);

Or use the script @Sandeep Rajput provided in your workflow. Should work exactly the same (excluding the first and last line)


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.