Abort the incident record when related change is in new state

Chaithanya
Tera Contributor

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..");

    current.setAbortAction(true); 
    }

 

The above script takes reference and let me know the changes.

Thanks,

Chaitanya.

3 REPLIES 3

Barrilito van D
Kilo Guru

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!

Mohith Devatte
Tera Sage
Tera Sage

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

Chetan Mahajan
Kilo Sage
Kilo Sage

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