Populate the members which is present in the Group

shubhi211
Tera Guru

In catalog item there is a

field name: In which Groups to be added/removed (this is Reference Field)

Field Name: Users to be removed (List collector)

 

So the requirement is: what ever group is being mentioned in "In which Groups to be added/removed"

In the field "Users to be removed" the group members name should be there in the list collector.Capture.PNG

 

below is what I have done, but with this under the field "Users to be removed" Group name is populating (instead of  group member name)

Capture2.PNG

3 ACCEPTED SOLUTIONS

MackI
Kilo Sage

HI @shubhi211 

 

I understand the scenario from the screenshot.Can you pls share the exact User Story and acceptence criteria that you try to achieve?

 

After that, please mark my reply as Helpful so that  I can prepare your catalogue item solution code within a day.It's going to be the Glide Alex script which I need to prepare 

MackI | ServiceNow Developer | 2 *Mainline Certification | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia

View solution in original post

Under In the field "Users to be removed" the group members name should be there in the list collector, instead of Group name.

 

Like in the above-mentioned case "Group name" is being populated.

Like in group there is 10 users so 10 times "Group name" is coming but instead 10 group number names should some under the list.

View solution in original post

SN_Learn
Kilo Patron
Kilo Patron

Hi @shubhi211 ,

 

Your reference qualifier is correct.

The change that have to do it as below:

1. Open the table [sys_user_grmember], then right click and select configure> table.

 

SN_Learn_0-1720961207528.png

 

2. Now, find the User field and set the display value to true

 

SN_Learn_1-1720961283959.png

 

 

Result will be as below:

 

SN_Learn_2-1720961354652.png

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

5 REPLIES 5

MackI
Kilo Sage

hi @shubhi211 

 

Concept


1. Reference Qualifier: You'll use a reference qualifier on the "Users to be removed" list collector variable. This qualifier will dynamically filter the available users based on the group selected in the "Groups to be added/removed" variable.
2. Client Script: A catalog client script will be responsible for:
* Fetching the selected group's sys_id when the "Groups to be added/removed" field changes.
* Updating the reference qualifier on the "Users to be removed" list collector.
* Refreshing the list collector to display the filtered users.
Prerequisites
* Groups and Users: Ensure you have groups and users defined in your ServiceNow instance.
* Reference Field: The "Groups to be added/removed" variable should be a reference field referencing the sys_user_group table.
Implementation
1. Reference Qualifier
* Navigate to your catalog item.
* Open the "Users to be removed" variable.
* In the "Reference qual" field, enter this qualifier:

 

 

javascript:'sys_user_grmember.group=' + current.variables.group_to_be_added_removed; // Replace 'group_to_be_added_removed' with your variable's actual name

 

Important Note 

 

List Collector Configuration
* Display True/False: Navigate to the dictionary entry for the sys_user_grmember table (the table your list collector is referencing). Make sure the user field has "Display" set to true. This tells ServiceNow to use the user's name as the display value in reference fields.
* Attributes: In the "Attributes" field of your "Users to be removed" list collector variable, add the following:
This configures the list collector to:
* Use the name field for autocomplete suggestions (ref_ac_columns=name).
* Enable searching within those autocomplete suggestions (ref_ac_columns_search=true).

 

ref_ac_columns=name;ref_ac_columns_search=true

 


2. Catalog Client Script
* Create a new Catalog Client Script:
* Name: (e.g., "Filter Users by Group")
* Catalog Item: (Your catalog item)
* Type: OnChange
* Variable Set: (If applicable)
* Variable Name: group_to_be_added_removed // Replace with your variable's actual name

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return; // Don't run while loading or if no group is selected
    }

    // Get the sys_id of the selected group
    var ga = new GlideAjax('GetGroupSysID');
    ga.addParam('sysparm_name', 'getGroupSysID');
    ga.addParam('sysparm_group_name', newValue); // Pass the group name
    ga.getXML(updateListCollector); 
}

function updateListCollector(response) {
    var answer = response.responseXML.documentElement.getAttribute('answer');
    var userGR = g_form.getReference('users_to_be_removed'); // Get the reference field
    userGR.setReferenceQual('sys_user_grmember.group=' + answer);
    userGR.setDisplayValue(''); // Clear previous display value (if any) 
    g_form.clearValue('users_to_be_removed');
}

 

 

 

 


3. Script Include (GetGroupSysID)
* Create a new Script Include:
* Name: GetGroupSysID
* Accessible from: All application scopes
* Script:

 

var GetGroupSysID = Class.create();
GetGroupSysID.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getGroupSysID: function() {
        var groupName = this.getParameter('sysparm_group_name');
        var gr = new GlideRecord('sys_user_group');
        gr.addQuery('name', groupName);
        gr.query();
        if (gr.next()) {
            return gr.sys_id;
        }
        return '';
    }

});

 


Explanation
1. Reference Qualifier: Dynamically filters users based on the selected group.
2. Client Script:
* Triggers when the "Groups to be added/removed" field changes.
* Calls the Script Include to get the selected group's sys_id.
* Updates the list collector's reference qualifier with the sys_id.
* Clears the list collector to reflect the new filter.
3. Script Include:
* Fetches the sys_id of the group based on its name.

 

 

A small request from my end, If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community

MackI | ServiceNow Developer | 2 *Mainline Certification | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia