The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can hide group details based on catalog item

Lakshmi53
Tera Contributor

Hi All,

 

I have a variable set. In that variable set I have a field is requested for.

I used that variable set in all catalog items. But based on catalog item few of the users I need to hide on requestor variables.

 

How can I do that. I tried with reference qualifier and script include but it's not working 

8 REPLIES 8

i written below script but not working

 

javascript: new Hideuser().getUser(current.cat_item.sys_id);

 

var Hideuser= Class.create();
Hideuser.prototype = {
    initialize: function() {},
    getUser: function(catItemId) {
        var user= [];

        if (catItemId== '7899999') { //sys_id of the catalog

            var info = new GlideRecord('sys_user');
            info.addEncodedQuery('active=true');
            info.addEncodedQuery('sys_id!=123');
            info.query();
            while (info.next()) {
                user.push(info.sys_id.toString());
            }
            return 'sys_idIN' + user.join(',');
        } else {
            return 'operational_status=1';
        }
    },

    type: 'Hideuser'
};

@Lakshmi53 in your script include try something like below.

 

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

    getUser: function(catItemId) {
        var user = [];

        if (catItemId === '7899999') { 
            var info = new GlideRecord('sys_user');
            info.addEncodedQuery('active=true^sys_id!=123'); 
            info.query();

            while (info.next()) {
                user.push(info.sys_id.toString()); 
            }
            return user.length > 0 ? 'sys_idIN' + user.join(',') : 'sys_idINempty';
        } else {
            return 'operational_status=1'; 
        }
    },

    type: 'Hideuser'
};

 Please mark my answer correct and helpful if this works for you.

I varified through the logs catItemId I am receiving undefined 

Omkar Mone
Mega Sage

Hello Lakshmi,

 

It would be best to do it with Client callable Script include and onLoad client script to achieve this like below.

 

Script include

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

    getRequestorVisibility: function() {
        var userId = this.getParameter('sysparm_user_id');
        var usersToHide = ['USER_SYS_ID_1', 'USER_SYS_ID_2'];

        return usersToHide.includes(userId) ? 'true' : 'false';
    },

    type: 'HideRequestor'
});

 

On load client script 

 

function onLoad() {
    var userId = g_user.userID;
    var ga = new GlideAjax('HideRequestor');
    ga.addParam('sysparm_name', 'getRequestorVisibility');
    ga.addParam('sysparm_user_id', userId);

    ga.getXMLAnswer(function(response) {
        var shouldHide = response.responseXML.documentElement.getAttribute("answer");

        if (shouldHide === 'true') {
            g_form.setDisplay('requested_for', false);
        } else {
            g_form.setDisplay('requested_for', true);
        }
    });
}

 

Hope this helps.