Name
global.MatchingDimensionSkillLevel
Description
Dimension to process skills level gap.
Script
var MatchingDimensionSkillLevel = Class.create();
MatchingDimensionSkillLevel.prototype = Object.extendsObject(AbstractMatchingDimension, {
process : function(task, users, taskFieldValues, args){
/* Skills in taskFieldValues does not contain level information hence we need to query task_m2m_skill table to get the skill information along with the required level in order to calculate the total skill level gap and rank the agents accordingly. */
var skillsRequired = this.getTaskSkills(task.sys_id);
var returnUsers = {};
if(skillsRequired.size() == 0)
{
for(var i=0;i<users.length;i++){
var ratingObj = {};
ratingObj.rating = 1.0;
ratingObj.displayValue = " 0 / 0";
ratingObj.detailedDisplayValue = "Task has no skills";
returnUsers[users[i]] = ratingObj;
}
return returnUsers;
}
/* Get the list of qualified agents sorted in skill level gap in ascending order.
Skill level gap is an aggregated level gap between the required skill level for the task and agent's skill level. We need to find the agent who is the closest to the required skill level for the particular task hence we should use the least level gap for the most optimum agent */
try {
var agentRanking = new SNC.UserSkillRanking();
var qualifiedAgents = JSON.parse(agentRanking.getQualifiedRankedUsers(JSON.stringify(skillsRequired), JSON.stringify(users), 'LEAST_SKILL_LEVEL_GAP', true));
// since the returned list is in sorted order by the level gap, the last agent in the list would have the highest level gap out of all
var highestLevelGap = 0;
if(qualifiedAgents.length > 0)
highestLevelGap = (qualifiedAgents[qualifiedAgents.length - 1]).total_skill_level_gap;
for(var j = 0; j < qualifiedAgents.length; j++) {
var rateObj = {};
var levelGap = qualifiedAgents[j].total_skill_level_gap;
rateObj.rating = highestLevelGap > 0 ? levelGap/highestLevelGap : 0;
rateObj.value = levelGap;
rateObj.displayValue = " Total skill level gap is " + levelGap;
rateObj.detailedDisplayValue = "Total skill level gap : " + levelGap + ". Number of skills matching level : " + qualifiedAgents[j].num_skills_matching_level + ".";
returnUsers[qualifiedAgents[j].sys_id] = rateObj;
}
} catch(err) {
gs.error('Exception caught while collecting agent skill level gap ' + err);
}
return returnUsers;
},
getTaskSkills : function(task){
var skills = [];
if(gs.nil(task))
return skills;
var gr = new GlideRecord('task_m2m_skill');
gr.addQuery('task', task);
gr.query();
while(gr.next()){
var skill = {
'sys_id' : gr.getValue('skill'),
'level' : gr.getValue('skill_level'),
'is_mandatory' : Boolean(gr.mandatory)
};
skills.push(skill);
}
return skills;
},
type: 'MatchingDimensionSkillLevel'
});
Sys ID
f40eb8fd738033005e4a73a24ff6a774