UI Action for detecting if Change record Ci is attached to any open incident already.

Gk1503
Tera Contributor

Hi All,

We have an requirement to create UI action visible on assess state if Change record Ci is attached to any open incident already then it will give a info message on change request form that like "This CI is already attached to an open Incident : INC001202.

2 REPLIES 2

Brian Lancaster
Tera Sage

I'm not sure I fully understand. Why would you want to alert on a Change Record that a CI is associated with an incident? Most likely that would make sense because the change could be fixing the incident.

shloke04
Kilo Patron

Hi @Gk1503 ,

You can achieve this using the sample code available below:

var getDetails = checkIncidentCI();
gs.addInfoMessage('This CI is already attached to an open Incident :' + getDetails);
action.setRedirectURL(current);

function checkIncidentCI(){
	var incArr = [];
var inc = new GlideRecord('incident');
inc.addQuery('cmdb_ci',current.cmdb_ci);
inc.query();
while(inc.next()){
incArr.push(inc.number.toString());
}
return incArr;
}

 

Add a condition to the UI action as below to validate the assess state:

current.state == -4

 

shloke04_0-1714406252079.png

Result:

shloke04_1-1714406283528.png

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke