Catalog item

swatis22
Tera Contributor

How can I make the few values in the dropdown field visible to a particular team?

3 REPLIES 3

anshu_mohanty13
Giga Contributor

You can handle this by creating an onChange Catalog Client Script to manage hiding the dropdown values dynamically.

 

The approach you need to follow:

1. Create a Script Include on the server side to identify whether the current user belongs to a particular assignment group or team. This keeps your server-side logic clean and reusable.

 

2. In your onChange Catalog Client Script, use GlideAjax to call that Script Include. Once you get the response back on the client side confirming whether the user is part of that specific team or assignment group, you can then show or hide the relevant dropdown values accordingly based on your requirement.

 

 

namanajain
Mega Guru

To make specific dropdown values visible only to a particular team in a Catalog Item, you should use a Catalog Client Script (onLoad).

This approach allows you to dynamically remove unwanted options for users who are not part of the target group, while keeping the default choices available for authorized users.

function onLoad() {
    var userGroups = g_user.groups; // list of group sys_ids

    // Replace with your team (group) sys_id
    var targetGroup = 'xxxxxxxxxxxxxxxxxxxx';

    if (!userGroups.includes(targetGroup)) {
        // Remove restricted choices for users NOT in the group
        g_form.removeOption('dropdown_field_name', 'value_1');
        g_form.removeOption('dropdown_field_name', 'value_2');
    } else {
        // Do nothing → Valid group users will see all configured choices
    }
}

Tanushree Maiti
Tera Patron

Hi @swatis22 

 

  1. Create a onLoad Ctalog Client script
  • Navigate to System Evolution > Client Scripts and click New.
  • Set the Table to your target table
  • Set the Type to onLoad

 

function onLoad() {

    var targetGroupSysId = '<YOUR_GROUP_SYS_ID>';

        var ga = new GlideAjax('GroupUtils');

    ga.addParam('sysparm_name', 'isUserInGroup');

    ga.addParam('sysparm_group_id', targetGroupSysId);

    ga.getXMLAnswer(function(response) {

      var answer = response.responseXML.documentElement.getAttribute("answer");

         if (answer == 'false') {

            g_form.removeOption('u_dropdown', 'value1_to_hide'); //Replace with your drop down field

            g_form.removeOption('u_dropdown', 'value2_to_hide');

        }

    });

}

 

2. Create a Script include

  • Navigate to System Definition > Script Includes and click New.
  • Set the Name to GroupUtils 
  • Check the Client callable box

 

var GroupUtils = Class.create();

GroupUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

        isUserInGroup: function() {

        var groupId = this.getParameter('sysparm_group_id');

        var userId = gs.getUserID();       

        var gr = new GlideRecord('sys_user_grmember');

        gr.addQuery('group', groupId);

        gr.addQuery('user', userId);

        gr.query();       

        return gr.hasNext();

    },   

    type: 'GroupUtils'

});

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti