- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 01:47 PM
I have a Business Rule that takes part of the short description (a location), and puts it in our location field. This works from an email with subject Button Press - Laptop Laptop - UH07311. The Business Rule works. Further below is a script include that handles all of our routing for different Desktop Technicians depending on location, contract, etc... The script include is called by client scripts. Is there away to call it on the server side as well?
(function executeRule(current, previous /*null when async*/) {
var str = current.getValue('short_description');
var loc = str.substr(30);
if(str.indexOf("Button Press - Laptop Laptop -") == 0)
{
current.location.setDisplayValue(loc.trim());
current.cmdb_ci.setDisplayValue('Desktop MW');
current.u_incident_type.setDisplayValue('Fault/Failure');
current.u_issue.setDisplayValue('Other');
}
})(current, previous);
Script Include below:
var utsw_AJAXAssignmentRouting = Class.create();
utsw_AJAXAssignmentRouting.prototype = Object.extendsObject(AbstractAjaxProcessor, {
incidentRouting : function(){
//couldn't get the object to pass in, so rebuilding object to keep flow.
var json = new JSON();
var routingInfo = {};
routingInfo.ci = this.getParameter('sysparm_ci');
routingInfo.location = this.getParameter('sysparm_location');
routingInfo.issue = this.getParameter('sysparm_issue');
routingInfo.unit = this.getParameter('sysparm_unit');
routingInfo.contract = this.getParameter('sysparm_contract');
routingInfo.workarea = this.getParameter('sysparm_workarea');
var incRouting; //setup var in global space to be used for GlideRecord to incident routing table
for(x in routingInfo){
gs.log("routinInfo --> " + x + " : " + routingInfo[x], 'utsw_AJAXAssignmentRouting');
//jslog("routinInfo --> " + x + " : " + routingInfo[x], 'utsw_AJAXAssignmentRouting');
}
// if CI has unit, find match and return value. This overrides all other assignment rules.
if(routingInfo.unit != ''){
var ciUnit = new GlideRecord('u_incident_routing');
ciUnit.get('u_unit', routingInfo.unit);
return json.encode([ciUnit.u_assignment_group.sys_id.toString(), ciUnit.u_assignment_group.name.toString()]);
}
// if contract is filled, send to different assignment group
if(routingInfo.contract != ''){
var ciUnit = new GlideRecord('u_incident_routing');
if (ciUnit.get('u_contract', routingInfo.contract)) {
return json.encode([ciUnit.u_assignment_group.sys_id.toString(), ciUnit.u_assignment_group.name.toString()]);
}
}
// if workarea is filled, send to different assignment group
if(routingInfo.workarea != ''){
var ciUnit = new GlideRecord('u_incident_routing');
if (ciUnit.get('u_work_area', routingInfo.workarea)) {
return json.encode([ciUnit.u_assignment_group.sys_id.toString(), ciUnit.u_assignment_group.name.toString()]);
}
}
// if we have an issue, use it for assignment
if(routingInfo.issue != ''){
incRouting = new GlideRecord('u_issue_routing');
incRouting.addQuery('u_issue', routingInfo.issue);
incRouting.addQuery('u_configuration_item', routingInfo.ci);
incRouting.query();
if(incRouting.next()){
return json.encode([incRouting.u_assignment_group.sys_id.toString(), incRouting.u_assignment_group.name.toString()]);
}
}
//grab Service Desk group so we can use it
var serviceDesk = new GlideRecord('sys_user_group');
serviceDesk.get('Service Desk');
// grab CI so we can work with it on subsequent checks.
var ci = new GlideRecord('cmdb_ci');
ci.get(routingInfo.ci);
//gs.log('Configuration Item: ' + ci.name + ", Special: " + ci.u_special, 'utsw_AJAXAssignmentRouting');
// get Location record so we can work with it.
var location = new GlideRecord('cmn_location');
location.get(routingInfo.location);
// see if CI is special and assign accordingly
if(ci.u_special == true){
gs.log("CI SPECIAL: " + ci.name + ", Special: " + ci.u_special + ", Support Group: " + ci.support_group.name, 'utsw_AJAXAssignmentRouting');
//jslog("CI SPECIAL: " + ci.name + ", Special: " + ci.u_special + ", Support Group: " + ci.support_group.name, 'utsw_AJAXAssignmentRouting');
//see if there is a location that we need to use.
incRouting = new GlideRecord('u_incident_routing');
incRouting.addNotNullQuery('u_location');
incRouting.query();
// if we find a location matching return assignment group
while(incRouting.next()){
//gs.log('In while loop looking for location' + incRouting.sys_id, 'utsw_AJAXAssignmentRouting');
if(location.name.indexOf(incRouting.u_location) > -1){
return json.encode([incRouting.u_assignment_group.sys_id.toString(), incRouting.u_assignment_group.name.toString()]);
}
}
// if there is no issue value or matching location, look to the support group of the CI and use it
if(ci.support_group != ''){
//gs.log('CI Special: Configration Item: ' + ci.name + ' Support Group: ' + ci.support_group.name + ' : ' + ci.support_group.sys_id, 'utsw_AJAXAssignmentRouting');
return json.encode([ci.support_group.sys_id.toString(), ci.support_group.name.toString()]);
// if there is no support group use the service desk
} else {
return json.encode([serviceDesk.sys_id.toString(), serviceDesk.name.toString()]);
}
//if CI not special, return support group if exist, and then service desk
} else {
if(ci.support_group != ''){
//gs.log('CI NOT Special: Configration Item: ' + ci.name + ' Support Group: ' + ci.support_group.name + ' : ' + ci.support_group.sys_id, 'utsw_AJAXAssignmentRouting');
return json.encode([ci.support_group.sys_id.toString(), ci.support_group.name.toString()]);
} else {
return json.encode([serviceDesk.sys_id.toString(), serviceDesk.name.toString()]);
}
}
}
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 12:48 PM
Your Script Include is a client-callable SI. It doesn't work the same when called server-side, if I'm not mistaken. Try making a non-client-callable version, and have the client-callable one invoke it for GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 12:48 PM
Your Script Include is a client-callable SI. It doesn't work the same when called server-side, if I'm not mistaken. Try making a non-client-callable version, and have the client-callable one invoke it for GlideAjax.