how to hide/show list collector variable options for only two groups

raj765_32
Tera Contributor

hi can anyone help me for scenario for there is a list collector variable in catalog item with name ' access needed' and it is referencing access table, there are options with name ' okta retail' and ' okta prod' i want to show these two options in list collector variable only for process specilist group memners and service now dev group.

 

i.e 

Only allow ServiceNow Development and Process Specialist groups to see this option in list collector variable and hide from view for all other group members

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hi @raj765_32 

 

If possible, can you share some screenshot please...!!!

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

sure below is screen shot service desk okta prod and service desk okta reail need to be show only for two groups

Hi @raj765_32 

 

1.You can write script include to check group membership of current user & return the query depending upon that.

2.use reference qualifier on list collector variable to call that script include.

 

Script include :

Name : accessUtils

Function : getAccessNeeded

 

 

var accessUtils = Class.create();
accessUtils.prototype = {
    initialize: function() {},


    /*1. Get access needed depending upon user group */
    getAccessNeeded: function(userId) {

        /*2. Declare variable to return value */
        var query;

        /*3. Check group membership of user */
        var grMem = new GlideRecord('sys_user_grmember');
        grMem.addEncodedQuery('group.nameINServiceNow Development,Process Specialist^user=' + userId);
        grMem.query();

        if (grMem.query()) {

            /*4.1 User is member of groups */
            query = "put your query here if user is member of group";
        } else {
            /*4.2 User is not memeber of groups */
            query = "put your query here if user is not member of group";
            /*for example - 
            query = "fieldName!=okta retail^ORfieldName!=okta prod";
            */
        }
        /*4. Return the query */
        return query;

    },
    type: 'accessUtils'
};

 

 

 

Reference Qualifier : 

 

 

javascript: new accessUtils().getAccessNeeded(gs.getUserID());

 

 

VishalBirajdar_0-1697519676285.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

no this is not working, can you help me with client scripts and display business rule?