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

Guido Bernuetz
Giga Guru

It's managed with ACL's. Which ticket type you mean? Check ACL's for right table.

I am not a helpful hunter.
I will always try to give a meaningful and valid answer.

Its Mainly Incidents and RITMs

Nitesh A
Tera Expert

Hello @Lesiba Kgomo 

 

try using onLoad Client script:

function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('state') == '3') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
// by default the mandatory fields can not be set as readonly
// Make the field non-mandatory before making it readonly
g_form.setMandatory(fields[x], false);
g_form.setReadOnly(fields[x], true);
}
}
}

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Nitesh

Utpal Dutta
Tera Guru
Tera Guru

Hi Lesiba,

If it is non editable in form view, then how are you changing the values of fields?