Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Prevent State from changing when ticket is inactive

Lesiba Kgomo
Tera Contributor

Hi,

 

I am faced with a bit of an issue where an inactive ticket can have comments updated, state changes even though it remains inactive (uneditable in form view). tried playing around with BRs and not getting the desired results. 

Any suggestions?

1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage

Hi @Lesiba Kgomo ,

 

Hope you are doing great.

To prevent the state from changing when a user responds to an inactive ticket, I would recommend Before Business Rule. This approach allows us to intervene before the state is updated and apply the necessary logic to prevent the change.

example code snippet that you can utilize in your ServiceNow instance:

(function executeRule(current, previous /*, gs*/) {
   if (current.state == 4 /*Inactive*/ && current.comments.changes()) {
      // Reset the changes to prevent the state from being updated
      current.comments.revert();
      
      // Optionally, you can display an error message to the user
      gs.addErrorMessage("You are not allowed to update comments on an inactive ticket.");
   }
})(current, previous /*, gs*/);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

6 REPLIES 6

Hi, For example from list view it moves the ticket to active and editable and with email response from users it changes the state only and Active remains false. i need a way to prevent the state from changing when a user responds to an inactive ticket

Riya Verma
Kilo Sage

Hi @Lesiba Kgomo ,

 

Hope you are doing great.

To prevent the state from changing when a user responds to an inactive ticket, I would recommend Before Business Rule. This approach allows us to intervene before the state is updated and apply the necessary logic to prevent the change.

example code snippet that you can utilize in your ServiceNow instance:

(function executeRule(current, previous /*, gs*/) {
   if (current.state == 4 /*Inactive*/ && current.comments.changes()) {
      // Reset the changes to prevent the state from being updated
      current.comments.revert();
      
      // Optionally, you can display an error message to the user
      gs.addErrorMessage("You are not allowed to update comments on an inactive ticket.");
   }
})(current, previous /*, gs*/);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma