Insert SLA
unknown
javascript
a year ago
2.1 kB
5
Indexable
var slaSysId='be20a2a03b99025018dc2e2a85e45a8d'; var caseSysId='9026ee203bf8461018dc2e2a85e45a29'; var grCase= new GlideRecord('x_kimsg_kion_finan_finance_coe'); grCase.get(caseSysId); var sla = new GlideRecord('contract_sla'); sla.addActiveQuery(); sla.addQuery('sys_id','IN',slaSysId); sla.query(); while(sla.next()){ gs.info('sla name: '+sla.name); processNewSLA(sla,grCase); } function processNewSLA(sla,grCase) { // If start condition matches this task and stop condition doesn't, // create task_sla if there isn't one if (!sla.start_condition) return; //var startConditionMatches = GlideFilter.checkRecord(current, sla.start_condition); //if (!startConditionMatches) // return; var stopConditionMatches = GlideFilter.checkRecord(grCase, sla.stop_condition); if (sla.stop_condition && stopConditionMatches) return; var taskSLA = new GlideRecord('task_sla'); taskSLA.addActiveQuery(); taskSLA.addQuery('task', grCase.sys_id); taskSLA.addQuery('sla', sla.sys_id); taskSLA.setLimit(1); taskSLA.query(); if (taskSLA.hasNext()) return; insertTaskSLA(sla,grCase); } function insertTaskSLA(sla,grCase) { // Get preferences for where to get time zone and schedule var schSource = sla.schedule_source + ''; var tzSource = sla.timezone_source + ''; var newTaskSLA = new GlideRecord('task_sla'); newTaskSLA.task = grCase.sys_id; newTaskSLA.sla = sla.sys_id; newTaskSLA.start_time = grCase.sys_updated_on; var scheduleId = SLASchedule.source(schSource, newTaskSLA); if (scheduleId) newTaskSLA.schedule = scheduleId; newTaskSLA.timezone = SLATimezone.source(tzSource, newTaskSLA); // explicitly use system timezone, if the above property points to an empty/null value if (!newTaskSLA.timezone) newTaskSLA.timezone = gs.getSysTimeZone(); newTaskSLA.start_time = Boolean(sla.retroactive) === true ? grCase[sla.set_start_to] : grCase.sys_updated_on; newTaskSLA.insert(); }
Editor is loading...
Leave a Comment