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-25-2024 05:49 PM
I tried a BR on the wm_order table, for insert and update, it seems to work
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gdt = new GlideDateTime();
var schedRec = new GlideRecord('cmn_schedule');
schedRec.addQuery('sys_id', '08fcd0830a0a0b2600079f56b1adb9ae'); // 8-5 weekdays
schedRec.query();
if (schedRec.next()) {
var sched = new GlideSchedule(schedRec.sys_id);
var gdt2 = new GlideDateTime(gdt);
if (sched.isInSchedule(gdt2)) {
gs.addInfoMessage("current " + gdt2 + " is in schedule");
}
else {
gs.addInfoMessage("current " + gdt2 + " is not in schedule");
}
}
})(current, previous);
I get the the what I expect based on the schedule. you have nothing going on with
if (sched.isInSchedule(gdt2)) {
} else {