- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015 10:32 AM
In an RITM, I have two variables (both reference). One is a user reference and the other is supposed to be a list of the groups of which this user is a member, with the ability to choose one and populate the field with the assignment group.
These variables are populated by someone reviewing the RITM after it has been entered as a catalog item. The variables referenced here are hidden on the catalog item, but not on the RITM.
I use an OnChange client script on the user name field to make sure the user name is updated properly. It appears to work correctly. Here it is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
g_form.setValue('variables.ccb_assignedto', newvalue);
}
This is the assignment group variable information.
I have tried 4 or 5 different script includes (all variations on the same theme, shown below) and they either return nothing or everything (a list of sys id's--not helpful).
Here is what I've tried:
Script Include #1:
function getCurrentUserGroups() {
var member = current.variables.ccb_assignedto;
var group_array = [];
var getgroups = new GlideRecord('sys_user_grmember');
getgroups.addQuery('user',member);
getgroups.query();
while(getgroups.next())
{
group_array.push(getgroups.getValue('group'));
}
return 'sys_idIN' + group_array.toString();
}
Script Include #2:
function getCurrentUserGroups(){
var member = current.variables.ccb_assignedto;
gs.log("this is member: "+member);
var group_ids = [];
var grm_rec = new GlideRecord('sys_user_grmember');
grm_rec.addQuery('user',member);
grm_rec.query();
while(grm_rec.next()){
// collect group sys_id's into array
group_ids.push(grm_rec.group.sys_id+'');
}
// return data
if(group_ids.length>0){
return 'sys_idIN'+group_ids+''; // return query using sys_ids of user's groups
}
else{
return 'sys_idIN'+'***'; // return query for no records
}
}
Script Include #3:
function getCurrentUserGroups(){
var answer = '';
var member = current.variables.ccb_assignedto;
gs.log('this is member: '+ member);
var groups = new GlideRecord('sys_user_grmember');
groups.addQuery('user', member);
groups.query();
while(groups.next()){
answer += ',' +memberGR.user;
}
return answer;
}
Script Include #4:
function returnCurrentUserGroup(){
var myUserObject = current.variables.ccb_assignedto;
var myUserGroups = myUserObject.getMyGroups();
var groupsArray = [];
var it = myUserGroups.iterator();
var i=0;
while(it.hasNext()){
var myGroup = it.next();
groupsArray[i]=myGroup;
i++;
}
return groupsArray;
}
I'm stuck. Please let me know if you need any more information.
Thanks so much,
Suzanne
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2016 08:48 AM
Hello everyone, yes this issue is resolved. Here is the script include:
function assignmentGroupUsers()
{
var group = current.variables.ccb_assmtgrp;
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group);
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('user'));
}
return 'sys_idIN' + user_array.toString();
}
The reference qualifier on the variable (a reference variable on the sys_user table) is javascript:assignmentGroupUsers().
Works perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015 11:14 AM
Suzanne,
You need to have the ccb_assgrp has a Reference to Groups table(sus_user_group) and have the script as:
var grp = '';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user.sys_id',current.variables.ccb_assignedto);
gr.query();
while(gr.next())
{
grp += ',' + grp.group.sys_id;
}
return 'sys_idIN' + grp;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015 11:34 AM
Mani,
Thanks for this info. Unfortunately it returned an empty list for a user that I know is in several groups.
Suzanne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015 11:50 AM
Suzzane,
Can you send me the screenshot of the variable 'Group' and your script include.
Also, can you keep log statements to see if everything is printing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015 11:59 AM
The orginal ccb_assgrp variable screen shot is in my first message. As per your suggestion (if I understood it correctly), i changed it to be this:
The script include is copied from your message:
function getCurrentUserGroups(){
var grp = '';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user.sys_id',current.variables.ccb_assignedto);
gr.query();
while(gr.next())
{
grp += ',' + grp.group.sys_id;
}
return 'sys_idIN' + grp;
}
I'll add some logs and see if i can get any further information.
Thanks so much for your response,
suzanne