g_user to get default group ?

hartr
Giga Contributor

I have setup a default support group field against sys_user for all of the ITIL users to record the primary support group that they belong to.

I'd like to use something like

g_form.setValue('assignment_group', g_user.u_default_grp);

or similar so that I can populate the cuurent users default group into the incident.assignment_Group field using a client UI Action.

Does anyone know if this is possible ?

1 ACCEPTED SOLUTION

Here's a better example. If you wanted to modify the assign to me UI Action to include the default group you would use:



current.assigned_to = gs.getUserID();
var myUser = new GlideRecord('sys_user'); //think there's a shortcut but couldn't think of it
if (myUser.get(gs.getUserID())) {
current.assignment_group = myUser.u_default_grp;
}
current.update();


View solution in original post

8 REPLIES 8

hartr
Giga Contributor

Umm .. on a similar note .. would it be possible to make a field on the User form mandatory if any Groups or Roles were related - perhaps with a client script ? Thanks !!!


Not sure I follow, but yes you query the users groups and roles in a client script then set mandatory fields.


I have a field on sys_user called "u_default_Group" . Which references the group table and should be filled in for all users that are a member of a group or role. I use the field in conjunction with an "Assign To Me" UI Action so that the system knows which group as well as user to assign a task to. This is the field I'd like to make the mandatory so that the UI Action always functions correctly. Would you be able to provide me an example again John ? Many thanks.


Not applicable

Russell, if I understood your mail and this post you want the default group to be mandatory on user records where the user is a member of a group or has a role? There are probably a number of ways to do this.
1. UI Policy. If you wanted to use UI policy you could add 2 fields to the sys_user table - u_has_role and u_has_group. Using this method means you could easily set a ui policy on the table to test either flag for true and then make the u_default_group mandatory. To update those flags you need to add a business rule to the group member table and user role table that set the flag to true on insert or updates of a membership or role record. However it would need to include exception processing for when a user is deleted - would need to test if any more entries exist and if not set the appropriate flag to false.... not too simple but doable in a couple of hours.

2. UI policy - there are script areas but I haven't used them - so not 100% sure what data is available and how the conditions work

3. Client script. Write an onload client script on the sys_user table that does a glide lookup on both tables and sets the field mandatory is either finds at least one record.
var gr = new GlideRecord('sys_user_has_role');
var vUser = g_form.getValue('name');
gr.addQuery ('user', vUser);
if (gr.next()) {
// found one
g_form.setMandatory(cant remember the syntax);
}
// repeat for the 'sys_user_grmember table - the 'user' in the addQuery might need to be a different field