Business rule that will create incident only if outside of scheduled hours (on insert of Work Order)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 03:20 PM
We are using CMMS, ITSM and have an integration with xmatters for oncall notification for incidents only.
Our use case is that a customer, after hours, submits a work order and answers a set of questions in a set way.. when they do it will trigger a business rule that looks at the short description, type of ticket and the priority - if it matches then it needs to create an incident.
I created a schedule that is being looked at to see if the current time is in the schedule or not. If it's not in the schedule then it should produce an incident. If it is within the schedule time then it does nothing.
This is working great on UPDATE of the work order..(obviously we won't actually run it on update eventually i was just testing - it isn't working on insert at all and i can't figure out why.)
Can someone look?
(function executeRule(current, previous /*null when async*/ ) {
var gdt = new GlideDateTime();
var schedRec = new GlideRecord('cmn_schedule');
schedRec.addQuery('sys_id', '44bc853f1b7b7dd4ed9711f72a4bcbed');
schedRec.query();
if (schedRec.next()) {
var sched = new GlideSchedule(schedRec.sys_id);
var gdt2 = new GlideDateTime(gdt);
if (sched.isInSchedule(gdt2)) {
} else {
var inc_gr = new GlideRecord('incident');
inc_gr.initialize();
inc_gr.state = '1';
inc_gr.parent = current.sys_id;
inc_gr.caller_id = current.opened_by;
inc_gr.u_affected_user = current.caller;
inc_gr.cmdb_ci = '61816a291bf464901ffc3153cd4bcbc5';
inc_gr.u_entity = current.u_facility;
inc_gr.category = 'htm';
inc_gr.subcategory = 'htm';
inc_gr.short_description = 'contact number for user : ' + current.u_callback_number + ' ' + inc_gr.caller_id.getDisplayValue() + ' ' + current.short_description;
inc_gr.description = current.description + '\n' + 'Best contact number for user : ' + current.u_callback_number;
inc_gr.assignment_group = current.asset.support_group;
inc_gr.contact_type = 'self-service';
var inc_id = inc_gr.insert();
inc_gr.setWorkflow(true);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 03:56 PM
Seems your problem may be related to the integration, have you created a new record with field values that meet the conditions of the BR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 03:59 PM
It's ServiceNow's cmms/hcls product so no integration - shared tables/extensions
And yep.. create a new work order that meets all the criteria and it does nothing in creating the incident.
Update that same work order with a comment or work note (just a period) and it will create the incident straight away.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 05:48 PM
I don't have a work order table to test, I see nothing wrong with your script (unless gdt2 is in the schedule).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 02:06 PM
Nope, not in the schedule 😐 i have no idea why it will work on update but not on create.