Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Outage creation from incident

Community Alums
Not applicable

Hi,

I want  outage to be created from incident using create outage context menu option. Tried below script in create outage ui action but its not working.

 

function outageAlreadyExists() {
var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.addQuery('task_number', current.sys_id);
outageGr.query();
return outageGr.hasNext();
}

var outageExists = outageAlreadyExists();
createOutageM2M(outageExists);

function createOutageM2M(outageExists) {
if (!outageExists) {
current.update();
var url = new CreateOutageUtil().getNewOutageLink(current);
action.setRedirectURL(url);
action.setReturnURL(current);
}
}

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

You can try the following way to hide the Create outage option if there is an Outage already exists with that Incident.

 

1. Create a Script Include like the one below:

 

AnveshKumarM_0-1696335056829.png

 

function checkIfOutageExists(inc){
	var outageGr = new GlideRecord('cmdb_ci_outage');
	outageGr.addQuery('task_number', inc);
	outageGr.query();

	if(outageGr.next()){
		return false;
	}
	return true;
}

 

 2. Now add this to condition field in UI Action as shown below:

(OOTB UI Action SYS_ID is : 18edfe530a0006d401d579b8ca27b3f1)

 

(current.getRecordClassName() == 'incident' || current.getRecordClassName() == 'problem') && current.active && checkIfOutageExists(current.sys_id)

 

AnveshKumarM_1-1696335231453.png

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

View solution in original post

5 REPLIES 5

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

You can try the following way to hide the Create outage option if there is an Outage already exists with that Incident.

 

1. Create a Script Include like the one below:

 

AnveshKumarM_0-1696335056829.png

 

function checkIfOutageExists(inc){
	var outageGr = new GlideRecord('cmdb_ci_outage');
	outageGr.addQuery('task_number', inc);
	outageGr.query();

	if(outageGr.next()){
		return false;
	}
	return true;
}

 

 2. Now add this to condition field in UI Action as shown below:

(OOTB UI Action SYS_ID is : 18edfe530a0006d401d579b8ca27b3f1)

 

(current.getRecordClassName() == 'incident' || current.getRecordClassName() == 'problem') && current.active && checkIfOutageExists(current.sys_id)

 

AnveshKumarM_1-1696335231453.png

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

Community Alums
Not applicable

not working

@Community Alums Can you try the Script Include code and name I Provided as is and the condition too?

Thanks,
Anvesh

Community Alums
Not applicable

Hi, tried with same script and added condition too in ui action , but still i can see create outage option eventhough outage is already created.

Shannu_0-1696337982921.png