Need help with Change Request - Change Management form

Harsh3842
Tera Contributor

Hi All,

I need help with a requirement - the requirement is on the change request form when we are moving from implement to review state if that change request has any associated change task auto or manual if the task is not either closed or cancelled the change request state should not move from implement to review state Now to fix it 
I wrote a Business Rule on change_request table, before update with condition state changes to review
This is the script that I have written

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

     var implementState = -1; // 'Implement'
     var reviewState = 0;     // 'Review'

    // Only block if trying to move from Implement to Review
   if (current.state == reviewState && current.state.changesFrom(implementState)) {

         var taskGR = new GlideRecord('change_task');
         taskGR.addQuery('change_request', current.sys_id);
         taskGR.addQuery('state', 'NOT IN', '3,4'); // Allow only Closed (3) and Cancelled (4)
         taskGR.query();

         if (taskGR.hasNext()) {
             gs.addErrorMessage("All Change Tasks must be closed or cancelled before moving to the Review state.");
             current.state = previous.state; // Revert to previous state
             gs.setAbortAction(true); // Block the update
         }
     }

 })(current, previous);
this is working fine but There is a flow attached to change request by name change normal implement due to it I am getting an error message on change task table.  if I am closing either of the change task which are auto created (post implementation testing or implementation)
How can I avoid it so that irrespective whether there is auto task or manual task the change request does not  move to review state unless until all the change task are closed
And the flow is OOTB




1 ACCEPTED SOLUTION

Ehab Pilloor
Mega Sage

Hi @Harsh3842,

If you want the Flow to not be activated when BR is running then add 

 if (taskGR.hasNext()) {
             taskGR.setWorkflow(false);// Disables the Flow on Change Task
             gs.addErrorMessage("All Change Tasks must be closed or cancelled before moving to the Review state.");
             current.state = previous.state; // Revert to previous state
             gs.setAbortAction(true); // Block the update
         }

However, you need to check if disabling the Flow doesnt hamper critical processes before moving forward.

 

Regards,

Ehab Pilloor

View solution in original post

8 REPLIES 8

Vasu20
Tera Contributor

Hi @Harsh3842 

If you have no tried, please write setWorkflow(false) in your business rule and try out.


Thanks and Regards,
Vasu

Vasu20
Tera Contributor

Hi @Harsh3842 

If you have no tried, please write setWorkflow(false) in your business rule and try out so that the flow designer does not trigger.


Thanks and Regards,
Vasudev

Ehab Pilloor
Mega Sage

Hi @Harsh3842,

If you want the Flow to not be activated when BR is running then add 

 if (taskGR.hasNext()) {
             taskGR.setWorkflow(false);// Disables the Flow on Change Task
             gs.addErrorMessage("All Change Tasks must be closed or cancelled before moving to the Review state.");
             current.state = previous.state; // Revert to previous state
             gs.setAbortAction(true); // Block the update
         }

However, you need to check if disabling the Flow doesnt hamper critical processes before moving forward.

 

Regards,

Ehab Pilloor

Nilesh Pol
Tera Guru

@Harsh3842 use taskGR.update(); after setting up values in your code.