When incident is resolved i need to update the Outage table with Outage type,Begin and End values

Rajamouly
Tera Expert

Upon Incident Resolution, the assignee will fill out Actual Start/Actual End and Outage Record type fields on the incident form and these fields will be populated automatically on the Outage record.

 

For this i have created after business rule, and mentioned the condition

 

Condition:urrent.incident_state.changesTo (6)

Script: 

(function executeRule(current, previous /*null when async*/) {

var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.setValue('begin', current.getValue('work_start'));
outageGr.setValue('end', current.getValue('work_end'));
outageGr.setValue('type', current.getValue('u_outage_record_type'));
outageGr.update();

})(current, previous);

 

Am i missing anything here, Please help me.

BR1.jpg

BR2.jpg

1 ACCEPTED SOLUTION

Hi @Rajamouly ,

Your script is correct and you can create one incident and make it to In progress.  Then update actual start and actual end, configuration and then resolve it.

It will update all the fields to that outage record.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

11 REPLIES 11

Mike_R
Kilo Patron
Kilo Patron

Is the Outage record already created at this point and related to the Incident, or are you attempting to create the Outage record through this business rule?

if the outage record is already created/associated, you can try this

var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.get('task_number', current.sys_id);
outageGr.setValue('begin', current.getValue('work_start'));
outageGr.setValue('end', current.getValue('work_end'));
outageGr.setValue('type', current.getValue('u_outage_record_type'));
outageGr.update();

 

 

If you are attempting to create the outage record, i would create a flow instead of a business rule.

Hello Mike,

 

Thanks for response, Yes Outage is created automatically through business rule,i have tried the code below but no luck

 

(function executeRule(current, previous /*null when async*/) {

var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.addQuery('task_number','current.sys_id');
outageGr.query();
if (outageGr.next()) {
outageGr.begin = current.work_start;
outageGr.end = current.work_end;
outageGr.type = current.u_outage_record_type;
outageGr.update();
}
})(current, previous);

Since you are trying to create a new record, try this

 

var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.initialize();
outageGr.setValue('task_number', current.sys_id);
outageGr.setValue('begin', current.getValue('work_start'));
outageGr.setValue('end', current.getValue('work_end'));
outageGr.setValue('type', current.getValue('u_outage_record_type'));
outageGr.insert();