Skip to main content
Version: 5.x

Business Rules Examples

Incident routing (ITSM) Example Script

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

/**
* This parameters have to be adjusted
*/
var socialMinerUrl = 'https://URL_TO_CISCO_SOCIALMINER/ccp/task/feed/FEED_ID';
var scriptSelector = 'TO_BE_ADJUSTED';


/**
* Change these parameters to make routing decisions
*/
// this is for identification on Cisco SocialMiner
var name = current.getValue('number') || '';
var title = current.getValue('number') || '';
var description = current.getValue('description') || '';
var tag = 'bs_connects_incident_routing';

// the call variables can be adjusted accordingly
var callVariables = {
call_variable_1: '', // empty variable
call_variable_2: 'ServiceNow Incident routing', // some fix string
call_variable_3: current.getValue('priority') || '', // Value of the Priority (the value is what is really written in the field, not what is displayed)
call_variable_4: current.getDisplayValue('short_description') || '', // Short description (can get striped as Cisco cVs can only be 40 bytes long)
call_variable_5: current.getDisplayValue('category') || '', // Display Value of the Category
call_variable_6: current.getDisplayValue('state') || '', // State
call_variable_7: new x_busag_cnx.GetAgentFromUser().getAgentIdOrEmpty(current.getValue('assigned_to')) || '', // Cisco Agent Id of the assigned agent (if any is available), to do some preferred agent routing
// it is important that the table and the unique Id are on any of the 10 call variables (or ECC)
// and the Media Routing configuration in the ServiceLayout is adjusted accordingly
// make sure these variables don't get overwritten in the script
call_variable_8: current.getTableName(),
call_variable_9: current.getUniqueValue(),
call_variable_10: '' // empty variable
};

/**
* Only change this if you really know what you are doing
*/
var xmlBody = '<Task><name>' + name + '</name><title>' + title + '</title><description>' + description + '</description><scriptSelector>' + scriptSelector + '</scriptSelector><customerUID /><requeueOnRecovery>false</requeueOnRecovery><tags><tag>' + tag + '</tag></tags><variables>';

for(var i = 1; i <= 10; i++) {
if (callVariables['call_variable_' + i]) {
xmlBody += '<variable><name>cv_'+ i +'</name><value>' + callVariables['call_variable_' + i] + '</value></variable>';
}
}

xmlBody += '</variables></Task>';

var sm;
var response;
var responseBody;

try {
sm = new sn_ws.RESTMessageV2();
sm.setEndpoint(socialMinerUrl);
sm.setHttpMethod('post');
sm.setRequestBody(xmlBody);
sm.setRequestHeader('Content-Type', 'application/xml');
response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
gs.info('Routed ' + current.getTableName() + ' with Id ' + current.getUniqueValue() + ' with status ' + status + ' and response ' + responseBody);
} catch(ex) {
responseBody = ex.getMessage();
status = 500;
gs.error('Failed to route ' + current.getTableName() + ' with Id ' + current.getUniqueValue() + ' with status ' + status + ' and response ' + responseBody);
}

})(current, previous);

Case routing (CSM) Example Script

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

/**
* These parameters have to be adjusted
*/
var socialMinerUrl = 'https://URL_TO_CISCO_SOCIALMINER/ccp/task/feed/FEED_ID';
var scriptSelector = 'TO_BE_ADJUSTED';


/**
* Change these parameters to make routing decisions
*/
// this is for identification on Cisco SocialMiner
var name = current.getValue('number') || '';
var title = current.getValue('number') || '';
var description = current.getValue('description') || '';
var tag = 'bs_connects_case_routing';

// the call variables can be adjusted accordingly
var callVariables = {
call_variable_1: '', // empty variable
call_variable_2: 'ServiceNow Case routing', // some fix string
call_variable_3: current.getValue('priority') || '', // Value of the Priority (the value is what is really written in the field, not what is displayed)
call_variable_4: current.getDisplayValue('short_description') || '', // Short description (can get stripped off as Cisco cVs can only be 40 bytes long)
call_variable_5: current.getDisplayValue('contact_type') || '', // Display Value of the Channel
call_variable_6: current.getDisplayValue('product') || '', // Product
call_variable_7: new x_busag_cnx.GetAgentFromUser().getAgentIdOrEmpty(current.getValue('assigned_to')) || '', // Cisco Agent Id of the assigned agent (if any is available), to do some preferred agent routing
// it is important that the table and the unique Id are on any of the 10 callvariables (or ECC)
// and the Media Routing configuration in the Service Layout is adjusted accordingly
// make sure this variables don't get overwritten in the script
call_variable_8: current.getTableName(),
call_variable_9: current.getUniqueValue(),
call_variable_10: '' // empty variable
};

/**
* Only change this if you really know what you are doing
*/
var xmlBody = '<Task><name>' + name + '</name><title>' + title + '</title><description>' + description + '</description><scriptSelector>' + scriptSelector + '</scriptSelector><customerUID /><requeueOnRecovery>false</requeueOnRecovery><tags><tag>' + tag + '</tag></tags><variables>';

for(var i = 1; i <= 10; i++) {
if (callVariables['call_variable_' + i]) {
xmlBody += '<variable><name>cv_'+ i +'</name><value>' + callVariables['call_variable_' + i] + '</value></variable>';
}
}

xmlBody += '</variables></Task>';

var sm;
var response;
var responseBody;

try {
sm = new sn_ws.RESTMessageV2();
sm.setEndpoint(socialMinerUrl);
sm.setHttpMethod('post');
sm.setRequestBody(xmlBody);
sm.setRequestHeader('Content-Type', 'application/xml');
response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
gs.info('Routed ' + current.getTableName() + ' with Id ' + current.getUniqueValue() + ' with status ' + status + ' and response ' + responseBody);
} catch(ex) {
responseBody = ex.getMessage();
status = 500;
gs.error('Failed to route ' + current.getTableName() + ' with Id ' + current.getUniqueValue() + ' with status ' + status + ' and response ' + responseBody);
}

})(current, previous);