Abort the incident record when related change is in new state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 07:55 AM
Hi all,
I'm trying before update business rule to the incident table and the condition state is resolved, A user is not able to resolve the incident when the related change record is in a new state.
var gr = new GlideRecord("change_request");
gr.addEncodedQuery('number', current.rfc + "state=-5");
gr.query();
if (gr.next()) {
gs.addErrorMessage("your Change request is in new state.please work on it..");
The above script takes reference and let me know the changes.
Thanks,
Chaitanya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 12:32 AM
Hi,
I am not sure what your question is as you don't clearly state what is working or what is not working, but it is clear that your encoded query is not an encoded query, you made a little mix of a normal addquery and tried to add something.
Lookup the change request in the UI in a list and create a filter, copy that query filter and use that is the encoded query. See this link in step 4 how you can copy the encode query. That probably would fix something. And just run a background script to test your code and look step by step what the result is.
If you think my answer put you in the right direction or you appreciated my effort, please mark the response as Helpful (👍 )or mark my response as Correct (✅).
Thanks in advance! Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 12:37 AM
Hello @Chaithanya ,
YOU CAN TRY THIS CODE
if(current.rfc.state==5 || current.rfc.state=="5")
{
gs.addErrorMessage("your Change request is in new state.please work on it..");
current.setAbortAction(true);
}
Hope this helps
Mark my answer correct if this helps you
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 01:23 AM
Hello @Chaithanya ,
you can try below code.
(function executeRule(current) {
var gr = new GlideRecord("change_request");
gr.addQuery("sys_id", current.rfc); // rfc is field on incident table which refers change request
gr.addQuery("state", "!=", 1); // Check for change request not in 'New' state
gr.query();
if (gr.next()) {
gs.addErrorMessage("Your Change request is not in a 'New' state. Please work on it.");
current.setAbortAction(true);
}
})(current);
Kindly mark correct and helpful if applicable