- 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-23-2015 01:22 PM
Well, I put the script back the way it was to see if I received any messages. I'm actually getting undefined undefined undefined, for the working script as well, so I guess this has nothing to do with why it's not working. Of course, if I have 3 people in the group, the the undefined shows 3 lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2015 01:34 PM
Just to clarify - are you getting that undefined message still when using gs.addInfoMessage(userList[i].sys_id + " " + userList[i].name + " " + userList[i].count) ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015 05:19 AM
I ended up moving the query down in the script and added gs.addInfoMessage(userList[i].sys_id + " " + userList[i].name + " " + userList[i].count). I'm now seeing a list of all the members that are in that group and the number of incidents they have assigned to them but it's not querying for just this one group. These folks are actually in several service desk groups, so it's showing the number of incidents they have assigned to them for the other groups. It assigned to someone in the group but not the two members that I have selected for this assignment group.
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') {
//if (cg.user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1){
//cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1);
//cg.addQuery('user.u_service_dsk_workload', 'CONTAINS', '591f507cf07d4d0c0f323fc297cb7d10');
//cg.addQuery('user.sys_user.u_service_dsk_workload', 'IN', '591f507cf07d4d0c0f323fc297cb7d10');
//cg.addQuery('user.u_service_desk_workload', 'SD-Collaboration/Mobile');
cg.query();
while(cg.next()) {
var tech = cg.user.toString();
cg.addQuery('user.u_service_dsk_workload', 'CONTAINS', '591f507cf07d4d0c0f323fc297cb7d10');
//if (cg.user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1){
//}
cg.addQuery(user.u_service_dsk_workload.toString().indexOf("591f507cf07d4d0c0f323fc297cb7d10") > -1);
//if ('cg.user.u_service_dsk_workload', 'CONTAINS', '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);
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('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: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 08:20 AM
Sorry, I forgot to comment out that 2nd line. We're trying to see if the Service DSK Workload contains this assignment group, we have a business rule for each group with the condition only firing if the incident assignment group matches (long story). The Service Desk wants to be able to add certain folks to be in workload assignment and set them for certain groups. So, we added the list field instead of the drop down (which worked) but we could only select one group. Here's a screen shot of the old field and new field. I really appreciate all your help.