Change should not be canceled after implement state

VijayKummamuru
Tera Expert

I have a requirement Change should not be canceled after implement state. I  do not want to touch OOB state flow 

 

i have written BR - Before Insert and Update 

Condition - State changes to canceled 

 

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

    // Add your code here
    if (current.state =='Implement'){
        current.setAbortAction(true);
        gs.addErrorMessage('cannot cancel change from implement state');
    }

})(current, previous);

 

But this is by passing  my BR After giving cancelled reason and going to cancel state 

 

@itil @sndev @Change @Chaitanya5 

3 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@VijayKummamuru 

it's better to handle it via state flow for the change type, please discuss this with your customer

in your business rule you should add this condition

State Changes From Implement AND State Changes to Cancel

Script:

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

    // Add your code here
    current.setAbortAction(true);
    gs.addErrorMessage('cannot cancel change from implement state');

})(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

View solution in original post

Robert H
Mega Sage

Hello @VijayKummamuru ,

 

Are you using Change Models? If you do you can disable the Implement to Cancelled transition as shown below:

 

In the Change Model record open the "Implement" state:

RobertH_0-1744094491331.png

And then remove the "Implement to Cancel" transition:

RobertH_1-1744094564047.png

 

If you are not using Change Models you need to adjust your Business Rule: remove the advanced script and set the filter and actions as shown below:

 

RobertH_0-1744094769703.png

 

RobertH_1-1744094797074.png

 

Regards,

Robert

 

View solution in original post

Shivalika
Mega Sage

Hello @VijayKummamuru 

 

You have given wrong condition. it should have been "previous.state == 'implement' //backend name" - because the previous state was impleent and current state is canceled. 

 

I hope you got the error here. But I would say this script is not required. 

 

Just add below in the "When to run and in "Actions" Abort it"

 

Shivalika_0-1744101170689.png

 

 

Shivalika_1-1744101186743.png

 

I hope this answers your issue also, and proposes a better way as well 🙂

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

 

 

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@VijayKummamuru 

it's better to handle it via state flow for the change type, please discuss this with your customer

in your business rule you should add this condition

State Changes From Implement AND State Changes to Cancel

Script:

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

    // Add your code here
    current.setAbortAction(true);
    gs.addErrorMessage('cannot cancel change from implement state');

})(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

Robert H
Mega Sage

Hello @VijayKummamuru ,

 

Are you using Change Models? If you do you can disable the Implement to Cancelled transition as shown below:

 

In the Change Model record open the "Implement" state:

RobertH_0-1744094491331.png

And then remove the "Implement to Cancel" transition:

RobertH_1-1744094564047.png

 

If you are not using Change Models you need to adjust your Business Rule: remove the advanced script and set the filter and actions as shown below:

 

RobertH_0-1744094769703.png

 

RobertH_1-1744094797074.png

 

Regards,

Robert

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @VijayKummamuru 

 

Greetings!!

 

There are two things to consider:

  1. First, you can keep the 'Cancel UI Action' for the admin change. That should be easy to do.

  2. Second, there are a few scenarios you need to consider. These are examples based on my experience as a Change Manager:

    • Let's say a change just started, and within the next 5 minutes, an MI has been raised on the same CI, and the MIM states that the change will not move forward. In this case, what would the change state be?

    • Sometimes, due to complications, we need to cancel the change even if the implementation has started.

    • Also, if the change moves to the 'Implement  ' state and it's dependent on a vendor, but the vendor doesn't reach the site or hasn't logged in, what would the change state be?

So, it's better to keep the 'Cancel Change' option but limit it to the Change Manager or System Admin only.

*************************************************************************************************************
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]

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

Shivalika
Mega Sage

Hello @VijayKummamuru 

 

You have given wrong condition. it should have been "previous.state == 'implement' //backend name" - because the previous state was impleent and current state is canceled. 

 

I hope you got the error here. But I would say this script is not required. 

 

Just add below in the "When to run and in "Actions" Abort it"

 

Shivalika_0-1744101170689.png

 

 

Shivalika_1-1744101186743.png

 

I hope this answers your issue also, and proposes a better way as well 🙂

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY