Implementation task should not move to Cancelled on clicking on Review and error message to show up.

lakshmi9
Tera Contributor

Hi Community,

I have a requirement like,

 

  • When a user moves the Change Request to the Review state, the associated Implementation Task should not auto-cancel. If the system attempts to cancel the Implementation Task during this transition, it should be prevented, and an error message should be displayed to the user.
  • I’ve already tried a Business Rule on the Change Request to check if any task is already in the Cancelled state, but that doesn’t meet this requirement — because it doesn’t stop the Implementation Task from being cancelled as part of the transition.
  • Before Business Rule script:

 

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

    // Only act if state is changing to Review
    if (current.state.changesTo(0)) {
        var taskGr = new GlideRecord('change_task');
        taskGr.addQuery('change_request', current.sys_id);
        taskGr.addQuery('type', 'implementation');
        taskGr.addQuery('state', '4'); // 4 = Canceled
        taskGr.query();

        if (taskGr.hasNext()) {
            gs.addErrorMessage("Cannot move Change Request to Review while any Implementation Task is in Canceled state.");
            current.setAbortAction(true);  // Stop the transition
        }
    }

}) (current, previous);
 
 
lakshmi9_0-1754055576832.png

 

Could someone kindly guide me on how to achieve this?
I’d really appreciate your help.
1 REPLY 1

Chaitanya ILCR
Kilo Patron

Hi @lakshmi9 ,

 

I would say, find out how the change task is moving to the cancelled state first(check the BRs or the Flows) which is making it cancel and fix that (you can use the script tracer for BR related debugging)

 

but 

in this scenario 

 

you have to create the BR on the change_task table 

create a Before update BR on the change_task table and abort the action of cancelling when the associated change is in the review state

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya