- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:06 PM
Hello all,
I have an Assignment Group Field referencing to Group (sys_user_group) table . But I want to display only the groups that Requester is part of.
And if the Requester is part of only one group, it has to be Auto populated.
How can i achieve it ? please pour your insights.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 07:12 AM
Hi @Madhan007 ,
You cant call both function in single reference qualifier and you wanted to auto populate the Group if user has single group so you have to call it in default value of the same field otherwise autopopulate will not work .
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:44 PM - edited 03-13-2024 12:45 PM
Hello @Madhan007 ,
First of all, you have to define a reference qualifier in order to limit the list of group available
Concerning the auto-population, a client script should get the job done..
If you need more details about how to perform any of these task, feel free to let me know so that i provide some samples scripts for you..
**Please mark my answer helpful or correct if it applies.
Thank you!
JE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:49 PM
Hi @Jean-Emmanuel , Thanks for the reply.
It would help me a lot if you could provide some sample scripts
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 02:08 PM - edited 03-13-2024 02:14 PM
Step 1 : Create a script include (which provide all groups for a given user in a reference qualifier format)
var MyGroupUtils = Class.create();
MyGroupUtils.prototype = {
getUserGroupRefQual: function(userId) {
var answer = "";
var arr = gs.getUser().getUserByID(userId).getMyGroups().toArray();
var i = 0;
while (i < arr.length) {
if (answer == "") {
answer = arr[i];
} else {
answer = answer + "," + arr[i];
}
i++;
}
return 'sys_idIN' + answer;
},
type: 'MyGroupUtils'
};
Step 2 : Define your reference qualifier on assignment group field (if you are on a extended task table, be sure to edit override setting to avoid apply the logic on all task table)
For the type of the reference qualifier, choose "Advanced" and set the following value
javascript : new MyGroupUtils().getUserGroupRefQual(current.requester-field-name)
after these steps the values of Assignment group id dynamically updated depending of the requester.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 01:22 PM
Hi @Madhan007 ,
You can write a reference qualifier and script include to achieve this,
First if logged in user has more than one group tagged to him
Reference qualifier(advanced) on field Assignment group
javascript: new getAllMyGroups().getGroups()
Second if loggedin user has only one group,
In default value call the script include but second function,
javascript:new getAllMyGroups().getSingleGroup()
Script include:
var getAllMyGroups = Class.create();
getAllMyGroups.prototype = {
initialize: function() {},
getGroups: function() {
var sysId = gs.getUserID();
var ga = new GlideRecord('sys_user_grmember');
ga.addQuery('user', sysId);
ga.query();
var arr = [];
while (ga.next()) {
arr.push(ga.group.toString());
}
return 'sys_idIN' + arr.toString();
},
getSingleGroup: function() {
var sys = gs.getUserID();
var groupName;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', sys);
gr.query();
if (gr.getRowCount() == 1) {
if (gr.next()) {
groupName = gr.group.toString();
}
}
return groupName.toString();
},
type: 'getAllMyGroups'
};
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang