- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2015 11:20 AM
I'm trying to change our Assignment Based workload script to query a list collector field instead of our select box field. Tried several times (script below) but it's not working...:(
var assignTo = getLowestUser();
//gs.addInfoMessage("assigning to is " + assignTo);
current.assigned_to = assignTo;
function getLowestUser() {
var userList = new Array();
var cg = new GlideRecord('sys_user_grmember');
cg.addQuery('group', current.assignment_group);
if (current.assignment_group.getDisplayValue() == 'SD - Collaboration/Mobile') {
//cg.addQuery('user.u_service_desk_workload', 'SD-Collaboration/Mobile'); HERE'S THE PREVIOUS DROP DOWN SELECT FIELD
NOW TRYING TO QUERY A LIST FIELD. IF THE LIST COLLECTOR CONTAINS THIS ASSIGNMENT GROUP.
//cg.addQuery('user.u_service_dsk_workload', 'LIKE', '591f507cf07d4d0c0f323fc297cb7d10');
//cg.addOrCondition('user.u_service_dsk_workload', 'CONTAINS', '591f507cf07d4d0c0f323fc297cb7d10');
//cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") >-1);
cg.query();
while(cg.next()) {
var tech = cg.user.toString();
TRIED TO QUERY HERE.
//if (cg.user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") >-1){
//if (cg.user.u_service_dsk_workload, 'LIKE', '591f507cf07d4d0c0f323fc297cb7d10'){
var cnt = countTickets(tech);
//gs.addInfoMessage("Tech counts " + cg.user.name + ' ' + cnt + " " + tech);
userList.push( { sys_id: tech, name: cg.user.name, count: cnt } );
}
for(var i=0; i < userList.length; i++) {
//gs.addInfoMessage(userList.sys_id + " " + userList.name + " " + userList.count);
}
userList.sort(function(a, b) {
//gs.addInfoMessage("Sorting: " + a.sys_id + "(" + a.count + "); " + b.sys_id + "(" + a.count + ")");
return a.count - b.count; });
if (userList.length <= 0)
return "";
return userList[0].sys_id;
}
function countTickets(tech){
var ct = new GlideRecord('incident');
ct.addQuery('assigned_to',tech);
ct.addQuery('active',true);
ct.query();
return ct.getRowCount();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015 07:19 AM
Hello Andrea,
I think the problem (if I'm understanding the desired outcome correctly) might lie in both these lines:
cg.addQuery('user.u_service_dsk_workload', 'CONTAINS', '591f507cf07d4d0c0f323fc297cb7d10');
cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1);
Am I understanding correctly that you only want members that are just in this group? If so, I think the first query might just want to do a straight equals comparison by removing the 'CONTAINS' parameter, so just cg.addQuery('user.u_service_dsk_workload', '591f507cf07d4d0c0f323fc297cb7d10');
It looks like the 2nd query is doing the same thing as the first from what I can see, so it could probably just be removed. Also, if I'm incorrect in my understanding and you do want to you use the 'CONTAINS' parameter, I might still remove the 2nd line as it seems a bit redundant. I also think for the 2nd line if you do want to use it, you would want to split that comparison out into 3 comparison parameters. For instance: cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10"), '>', -1);
Let me know if trying either of these changes produces the desired results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015 09:06 AM
Ahh ok I understand now. So your contains query is just fine, since a user can contain service desk groups outside of just the one you are comparing on. I believe it is your incident query that is the issue.
function countTickets(tech){
var ct = new GlideRecord('incident');
ct.addQuery('assigned_to',tech);
ct.addQuery('active',true);
ct.query();
return ct.getRowCount();
If I understand correctly, you want the incidents assigned to the tech, but only for the actual assignment group is that correct? If so I believe you will just need to add an additional query here for the assignment group ct.addQuery('assignment_group','<whatever the proper group would be>'). Does this look correct or am I perhaps still a bit off here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015 11:24 AM
Looks like it's showing the correct number of Active Incidents assigned to each person in that group now, but the actual incident assigned to someone that didn't even have a group in the Service DSK Workload load field.
var assignTo = getLowestUser();
//gs.addInfoMessage("assigning to is " + assignTo);
current.assigned_to = assignTo;
function getLowestUser() {
var userList = new Array();
var cg = new GlideRecord('sys_user_grmember');
cg.addQuery('group', current.assignment_group);
if (current.assignment_group.getDisplayValue() == 'SD - Collaboration/Mobile') {
cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10"), '>', -1);
//cg.addQuery('user.u_service_desk_workload', 'SD-Collaboration/Mobile');
cg.query();
while(cg.next()) {
var tech = cg.user.toString();
var cnt = countTickets(tech);
gs.addInfoMessage("Tech counts " + cg.user.name + ' ' + cnt + " " + tech);
userList.push( { sys_id: tech, name: cg.user.name, count: cnt } );
}
for(var i=0; i < userList.length; i++) {
//gs.addInfoMessage(userList.sys_id + " " + userList.name + " " + userList.count);
gs.addInfoMessage(userList[i].sys_id + " " + userList[i].name + " " + userList[i].count);
}
userList.sort(function(a, b) {
//gs.addInfoMessage("Sorting: " + a.sys_id + "(" + a.count + "); " + b.sys_id + "(" + a.count + ")");
return a.count - b.count; });
if (userList.length <= 0)
return "";
return userList[0].sys_id;
}
function countTickets(tech){
var ct = new GlideRecord('incident');
ct.addQuery('assigned_to',tech);
ct.addQuery('assignment_group','591f507cf07d4d0c0f323fc297cb7d10');
ct.addQuery('active',true);
ct.query();
return ct.getRowCount();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015 07:14 PM
I believe it's working now..:) Ended up making changes in this part of the script. Thank you so much for all your help..
var tech = cg.user.toString();
if (cg.user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1){
var cnt = countTickets(tech);
//gs.addInfoMessage("Tech counts " + cg.user.name + ' ' + cnt + " " + tech);
userList.push( { sys_id: tech, name: cg.user.name, count: cnt } );
}
}
var assignTo = getLowestUser();
//gs.addInfoMessage("assigning to is " + assignTo);
current.assigned_to = assignTo;
function getLowestUser() {
var userList = new Array();
var cg = new GlideRecord('sys_user_grmember');
cg.addQuery('group', current.assignment_group);
//cg.addQuery('user.u_service_desk_workload', 'SD-Collaboration/Mobile');
cg.query();
while(cg.next()) {
var tech = cg.user.toString();
if (cg.user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1){
var cnt = countTickets(tech);
//gs.addInfoMessage("Tech counts " + cg.user.name + ' ' + cnt + " " + tech);
userList.push( { sys_id: tech, name: cg.user.name, count: cnt } );
}
}
for(var i=0; i < userList.length; i++) {
//gs.addInfoMessage(userList.sys_id + " " + userList.name + " " + userList.count);
//gs.addInfoMessage(userList[i].sys_id + " " + userList[i].name + " " + userList[i].count);
}
userList.sort(function(a, b) {
//gs.addInfoMessage("Sorting: " + a.sys_id + "(" + a.count + "); " + b.sys_id + "(" + a.count + ")");
return a.count - b.count; });
if (userList.length <= 0)
return "";
return userList[0].sys_id;
}
function countTickets(tech){
var ct = new GlideRecord('incident');
ct.addQuery('assigned_to',tech);
ct.addQuery('assignment_group','591f507cf07d4d0c0f323fc297cb7d10');
ct.addQuery('active',true);
ct.query();
return ct.getRowCount();
}