How to hide a few choice values- if logged in user belongs to a specific group

Amol Pawar
Tera Guru

Hi Experts,

 

I have a requirement like I have created a record producer. The first variable is a select box in which I have added 4 choices. I want to hide some choices if a logged-in user belongs to a group.

How can I achieve this?

 

Let me know if anyone has done similar to this requirement.

Regards,

Amol

1 ACCEPTED SOLUTION

Amol Pawar
Tera Guru

Hi All,

Thank you for your replies. I got the answer from the thread: 

https://www.servicenow.com/community/developer-forum/abstractajaxprocessor-undefined-maybe-missing-g...

 

Script Include:

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

    checkGroup: function() {
        var grp = gs.getUser().isMemberOf('DISCL - Reviewers');
        return grp;
    },

    type: 'checkGroupMember'
});
 
Client script:
function onLoad() {
    //Type appropriate comment here, and begin script below

    var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
    ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
    ga.getXML(callback);


    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert('Before if');
       

        if (answer == 'true') {
            alert('After if');
            g_form.removeOption('type_of_disclosure', 'Audits');

        }
    }
}

Thank you,

Amol

View solution in original post

12 REPLIES 12

Hi @Ankur Bawiskar,

Thank you for your reply. 

I have a requirement like I have created a record producer. The first variable is a select box in which I have added 4 choices. I want to hide some choices if a logged-in user belongs to a group.

How can I achieve this?

I can't use role in catalog client script due to licensing issues. How can I achieve this?

I was reading some of your answers on similar kind of thread like using a Display BR and Client Script but that was not working on my case. Should I create the BR and client script in Global scope only?

 

Thanks in advance,

Amol

@Amol Pawar 

you can use onLoad client script + GlideAjax

Inside the script include function check if user belongs to that group and return true/false

then inside onLoad check the value is true/false and then based on that remove the options

BR won't work for catalog form

script is present here. I hope you can modify it as per your requirement

Hide Question Choice based on logged in user belonging to group 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Amol Pawar
Tera Guru

Hi All,

Thank you for your replies. I got the answer from the thread: 

https://www.servicenow.com/community/developer-forum/abstractajaxprocessor-undefined-maybe-missing-g...

 

Script Include:

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

    checkGroup: function() {
        var grp = gs.getUser().isMemberOf('DISCL - Reviewers');
        return grp;
    },

    type: 'checkGroupMember'
});
 
Client script:
function onLoad() {
    //Type appropriate comment here, and begin script below

    var ga = new GlideAjax('checkGroupMember'); // Script Include Name here
    ga.addParam('sysparm_name', 'checkGroup'); // Your Function Name here
    ga.getXML(callback);


    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert('Before if');
       

        if (answer == 'true') {
            alert('After if');
            g_form.removeOption('type_of_disclosure', 'Audits');

        }
    }
}

Thank you,

Amol