When a user selects Assignment Group, Assign to field should Auto populate.

Rohith2
Tera Contributor

When users is Selecting any Assignment group assign to field should Auto populate member from the Selected group.
In assign to field it should not allow the name of Opened by. if Opened by is member of that particular group.

3 REPLIES 3

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Rohith2 

 

Firstly, As there is multiple group members so auto populating it won't be useful but OOTB its members are only shown in the choices. These was implemented by setting Dependent field as 'assignment_group' in Assigned To Dictionary Entry. So if this is your custom field or not  already implemented, you can try this.

 

Secondly, If you want to exclude Opened By user if that is member of group, you can use Advanced type Reference Qualifier (which comes in Advance View) and can right below line:

 

javascript: 'sys_id!=' + current.opened_by;

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please write the Onchange client script on assignment group. So as soon as assignment group is selected it would autopopulate the assigned to field with someone from the group.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var openedby = g_form.getValue('opened_by');

    var member = new GlideRecord('sys_user_grmember');
    member.addQuery('group', newValue);
    member.addQuery('user', '!=', openedby);
    member.query();
    while (member.next()) {
        var role = new GlideRecord('sys_user_has_role');
        role.addQuery('role', '282bf1fac6112285017366cb5f867469');
        role.addQuery('user', member.user);
        role.setLimit(1);
        role.query();
        if (role.next()) {
            g_form.setValue('assigned_to', role.user);
			break;
        }

    }
}

 

Now if you want to not allow anyone to select assigned to having the same name as opened by configure dictionary for assigned to field and write the below in the Ref qualifier of selecting advance(screenshot below:-) . roles=itil should be present as that is OOB filter and should not be removed.

 

javascript: 'roles=itil^sys_id!=' + current.opened_by;

 

Saurav11_0-1665298185746.png

 

Please mark my answer as correct based on Impact.

 

Rohith2
Tera Contributor