- 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
04-26-2016 01:44 AM
If this is not resolved then i think that the reason why this is not working is that the "assigned to" value is not passed to the script include
first you need to pass the value from your reference qual that you need in the script
This means that the reference qual should be:
javascript:getCurrentUserGroups(current.variables.ccb_assignedto)
In the script include where you call the function you pass the value to the script through a local variable
function getCurrentUserGroups(assigned){
var grp = '';
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user.sys_id', assigned);
gr.query();
while(gr.next())
{
grp += ',' + grp.group.sys_id;
}
return 'sys_idIN' + grp;
}
Then it should work as intended
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2016 12:26 AM
Hi Suzanne,
Did your issue solved?
Thanks
- 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.