- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 12:20 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 03:01 AM
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*/);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 12:30 AM
It's managed with ACL's. Which ticket type you mean? Check ACL's for right table.
I will always try to give a meaningful and valid answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 12:56 AM
Its Mainly Incidents and RITMs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 12:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 12:46 AM
Hi Lesiba,
If it is non editable in form view, then how are you changing the values of fields?
