- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 01:19 PM
On our incident form the Assignment Group field is mandatory. Once a group is entered their, only the members of that group can be selected in the Assigned to field. I would like to do this in the reverse, initially leaving the Assignment Group empty, adding a user in the Assigned To field and then under the magnifying glass for the Assignment Group field I would only see the group or groups that user is a member of. Any thoughts are appreciated.
Thanks,
Bill Cravey
HonorHealth
william.cravey@honorhealth.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 02:01 PM
We are currently doing this, and it works fantastically!
Here is how we make it work (we also use the same logic on other fields. We have a set of 4 hierarchical fields where each one is limited by the field/s directly adjacent to it).
On Assigned to:
Dependent on = assignment_group
On Assignment group:
Ref qualifier is set to: javascript:BackfillAssignmentGroup()
Script for BackfillAssignmentGroup():
function BackfillAssignmentGroup(){
var groupList = ' ';
var assignedTo = current.assigned_to;
//return all groups if the assigned_to value is empty.
if(assignedTo == ''){
//list of groups that have the "assignment group" type, and filter out inactive groups.
return 'typeLIKE188225e715480200abe63ac4a19e9dfa^active=true';
}
//sys_user_grmember has the user to group relationship
var grpGR = new GlideRecord('sys_user_grmember');
grpGR.addQuery('user',assignedTo);
grpGR.addEncodedQuery('group.typeLIKE188225e715480200abe63ac4a19e9dfa^group.active=true');
grpGR.query();
while(grpGR.next()) {
if (groupList.length > 0) {
//build a comma separated string of groups if there is more than one
groupList += (',' + grpGR.group);
}
else {
groupList = grpGR.group;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + groupList;
}
Please let me know if you have questions!
~Lindsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 02:01 PM
We are currently doing this, and it works fantastically!
Here is how we make it work (we also use the same logic on other fields. We have a set of 4 hierarchical fields where each one is limited by the field/s directly adjacent to it).
On Assigned to:
Dependent on = assignment_group
On Assignment group:
Ref qualifier is set to: javascript:BackfillAssignmentGroup()
Script for BackfillAssignmentGroup():
function BackfillAssignmentGroup(){
var groupList = ' ';
var assignedTo = current.assigned_to;
//return all groups if the assigned_to value is empty.
if(assignedTo == ''){
//list of groups that have the "assignment group" type, and filter out inactive groups.
return 'typeLIKE188225e715480200abe63ac4a19e9dfa^active=true';
}
//sys_user_grmember has the user to group relationship
var grpGR = new GlideRecord('sys_user_grmember');
grpGR.addQuery('user',assignedTo);
grpGR.addEncodedQuery('group.typeLIKE188225e715480200abe63ac4a19e9dfa^group.active=true');
grpGR.query();
while(grpGR.next()) {
if (groupList.length > 0) {
//build a comma separated string of groups if there is more than one
groupList += (',' + grpGR.group);
}
else {
groupList = grpGR.group;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + groupList;
}
Please let me know if you have questions!
~Lindsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 10:04 AM
Thank you. I am very new to SN and particularly java scripting. The first couple of steps on your instructions are simple but after that I don't know where to create this java script. I appreciate your assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 10:32 AM
Create a script include and put the script there.
If you do not use "group type" on your groups, it may not return anything. You'll have to adjust the line that filters by that anyway to use your own sys_id for that field type. The rest of it should work.
THe wiki will tell you how to get encoded queries and how to use glide records. Those will become friends of yours 🙂
~L
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2016 07:11 AM
Thank you, Lindsey. I got it to work with your help.