Make Assignment group dynamic

AhuelieW
Tera Contributor

Hello ServiceNow gurus, could you please help me ?

I've created a client script to auto populate the assignment_group based of the Assigned_to. In other words, you just have to type the fulfiller's name and his service group will get populated in the assignment_group. But that works well when the fulfiller only belongs to one service group.

My issue is when the fulfiller is a member of multiple groups. What I'd like to do is to only display the service groups he is a member of into the assignment_group

 

Let say for example that "Abel tuter" is a member of Service Desk and IT Device support. When you enter "abel " in the assigned_to, we only want to see these two service groups in the assignment_group instead of the list of all available service group (as shown in the pictures below)

 

AhuelieW_0-1756293712240.png

 

AhuelieW_1-1756293725747.png

 

 

1 ACCEPTED SOLUTION

Bhimashankar H
Mega Sage

Hi @AhuelieW ,

 

This is just opposite of showing only member of group which selected.

 

First go through the this you tube video Assignment group and Assignee .

 

The script include you can use.

getGroupOfAssignee: function(current) {
    // Get selected assignee user sys_id from the form
    var userId = current.assigned_to || '';

    if (!userId) {
        // No assignee selected, return no groups or all groups as per your need
        return "";
    }

    // Query sys_user_grmember where user=userId to get group sys_ids
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', userId);
    gr.query();

    var groupIds = [];
    while (gr.next()) {
        groupIds.push(gr.getValue('group'));
    }

    if (groupIds.length == 0) {
        // User is not a member of any groups, return no records
        return "";
    }

    // Build encoded query to filter assignment groups by user's groups and active status
    return 'active=true^sys_idIN' + groupIds.join(',');

}

 

as explained in video call this function from dynamic reference qualifier.

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

View solution in original post

5 REPLIES 5

Bhimashankar H
Mega Sage

Hi @AhuelieW ,

 

This is just opposite of showing only member of group which selected.

 

First go through the this you tube video Assignment group and Assignee .

 

The script include you can use.

getGroupOfAssignee: function(current) {
    // Get selected assignee user sys_id from the form
    var userId = current.assigned_to || '';

    if (!userId) {
        // No assignee selected, return no groups or all groups as per your need
        return "";
    }

    // Query sys_user_grmember where user=userId to get group sys_ids
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', userId);
    gr.query();

    var groupIds = [];
    while (gr.next()) {
        groupIds.push(gr.getValue('group'));
    }

    if (groupIds.length == 0) {
        // User is not a member of any groups, return no records
        return "";
    }

    // Build encoded query to filter assignment groups by user's groups and active status
    return 'active=true^sys_idIN' + groupIds.join(',');

}

 

as explained in video call this function from dynamic reference qualifier.

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Thank you @Bhimashankar H , this worked. Edited a bit the script and worked well. Thanks

Rafael Batistot
Tera Sage

Hi @AhuelieW 

In the field, assignment group,  needs to be a reference type in the dictionary 

In the "Dependent Field" aba try to insert  assigned to. I have the inverse here 

RafaelBatistot_0-1756325599364.png

 

Thanks, I tried that in the first place but didn't work. Thanks though.