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

Pradeep Thipani
Mega Sage

Hi @AhuelieW ,

 

check these reference accepted solutions:

https://www.servicenow.com/community/itsm-forum/need-to-have-assignment-group-only-show-groups-that-...

https://www.servicenow.com/community/itsm-forum/when-assigned-to-field-is-selected-then-groups-will-...

 

 

Currently by OOB, the assigned to members are determined by the selected assignment group. Therefore, your current requirement is to display the assignment groups when the 'assigned to' option is selected.

 

1) Open Data Dictionary of Assignment group. (Right click on assignment group field and select data dictionary).

 

1.1 Add assigned_to under dependence view section.

 

PradeepThipani_0-1756331414903.png

 

2) Open Data Dictionary of Assigned to. 

 

2.1 Remove the dependent field value empty.

PradeepThipani_1-1756331521155.png

 

 

Thanks,

Pradeep

 

 

 

 

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep