Retrieving group information to autopopulate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2014 09:42 AM
Hey guys, wondering if you can help me on what I'm doing wrong.
I've set up a default value on the Assignment Group field of the Task form, which would then be inherited by Incident, Problem, and Change. The idea here is that when the Change/Incident/Problem assigned group is autopopulated with one of the logged in user's groups (doesn't matter which one it is if the user is part of multiple groups). The user then has the option of reassigning it as the ticket is created.
I'm having trouble trying to get this to work. The issue here is that while the code itself is returning the correct sys_id of the group I want to save, the Assignment Group (which is a reference to sys_user_group) field doesn't seem to like it and doesn't populate the group field.
Here is the code. The Default value of Assignment Group is set up to be:
javascript:new GetAssignGroupForUser(gs.getUserID());
The GetAssignGroupForUsers script is as below:
var GetAssignGroupForUser = Class.create();
GetAssignGroupForUser.prototype = {
initialize: function(usrID) {
var grusr = new GlideRecord ('sys_user_grmember');
if (grusr.get('user', usrID))
{
var grp = newGlideRecord ('sys_user_group');
grp = grusr.group;
gs.log('Testing ' + grp);
return grp;
}
},
type: 'GetAssignGroupForUser'
};
For script reuse purposes, this is set up so that if any code requires a group based on a user, then it can look for it here as well.
I can tell you that the gs.log part reveals that grp is actually returning a sys_id for a group so that's what we want so I'm at a loss as to why Assignment Group doesn't seem to like the data returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2014 07:36 AM
I don't know if you found a solution or not, but you could set the default value to be:
javascript:var groups = gs.getUser().getMyGroups().toArray();groups[0];
That gets a list of the user's groups as an array of sys_ids (gs.getUser().getMyGroups().toArray()) and then selects the first one (groups[0]). No need for the Script Include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 01:55 PM
I was just checking on some unanswered questions and was wondering if you ever got this to work properly for you? Please remember to click on the "Helpful Answer" and/or "Correct Answer" buttons on the appropriate responses. This helps other members see if a valid answer was received.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 09:34 AM
Sorry, no correct answer buttons. Forgot to label this a question.
And I forgot what the original context was but I actually had to take a completely different approach to the code to make it work. Forgot what the original issue was.