Abort incident resolve if open change request in related records

Vijaykumar K
Tera Contributor

Hi everyone, as a OOTB we can add change request to incident under related records section. My request is how to restrict incident resolve if any open CR is there on change request field. CR should be at least on review state to resolve the incident.

 

I'm trying with below script but it's not working. Precisely it's working but abort action is working every time. So irrespective of CR state , transaction is aborting..

 

Pls help me here 

 

var gr = new GlideRecord("change_request");
gr.addEncodedQuery('number', current.rfc + "state=-5");
gr.query();
if (gr.next()) {
gs.addErrorMessage("Please close the CR and proceed..");
current.setAbortAction(true);
}

1 ACCEPTED SOLUTION

Harshal Aditya
Mega Sage

Hi @Vijaykumar K ,

 

Hope you are doing well.

 

No need to write a script please refer below screenshot -

 

HarshalAditya_0-1691688358467.png

 

HarshalAditya_2-1691688464180.png

 

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

Regards,
Harshal

 

View solution in original post

4 REPLIES 4

Viraj Hudlikar
Tera Sage
Tera Sage

Hello Vijaykumar K,

current.rfc will give you sys_id of CHG record so your encodedQuery should be something like gr.addEncodedQuery("sys_id="+current.rfc+"stateIN0,3");

First, try to filter the CHG record form LIST of the CHG table and copy the encoded query, and try to build as per your requirement.

Rampriya-S
Tera Guru
Tera Guru
var change_sysid = current.rfc;//pass the chage request sys_id
var gr = new GlideRecord("change_request");
gr.addEncodedQuery('stateNOT IN3,4');
gr.addQuery('sys_id',change_sysid);
gr.query();
if(gr.next()){
    gs.addErrorMessage("Please close the CR and proceed..");
    current.setAbortAction(true);
    }
Please mark thumbs up if you accept this solution!!
Best,
Rampriya S

Harshal Aditya
Mega Sage

Hi @Vijaykumar K ,

 

Hope you are doing well.

 

No need to write a script please refer below screenshot -

 

HarshalAditya_0-1691688358467.png

 

HarshalAditya_2-1691688464180.png

 

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

Regards,
Harshal

 

Vijaykumar K
Tera Contributor

Hello @Harshal Aditya .. thats what I'm looking for. Thanks a lot 🙂