Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

Sorry mate, not an expert. Give try to @Ayushi12 solution.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Amol Pawar,

gs.getUser().isMemberOf does not work in SCOPED APPLICATION.

Please refer to the link:

gs.getUser().isMemberOf(current.assignment_group) not working

If I was able to solve your query, please mark my answer as correct and helpful.

 

 

Ayushi12
Mega Sage

Hi @Amol Pawar ,
You can use the below onload client script and script include.

1. Onload Client Script:

function onLoad() {
   var grpmember = new GlideAjax('CheckuserGroup'); //script include name
    grpmember.addParam('sysparm_name', 'getgroup'); //function name
    grpmember.getXMLAnswer(getGroup);
    function getGroup(response) {
        if (response == 'true') {
            g_form.removeOption(<fieldName>, <choiceValue>);
}
else { g_form.addOption(<fieldName>, <choiceValue>);
}
}

2. Script Include

var CheckuserGroup = Class.create();
CheckuserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getgroup: function() {
        var usersysid = gs.getuserId();//getting logged in usersysid 
        var mem = new GlideRecord("sys_user_grmember");
        mem.addQuery('user', usersysid); //filtering current user
        mem.addQuery('group',<add group sys_id>); //add group sysid
        mem.query();
        if (mem.next()) {
            return true;
        } else {
            return false;
        }
    },
    type: 'CheckuserGroup'
});

Please mark my answer as helpful and correct if it helped.

 

Amol Pawar
Tera Guru

Hi @Ankur Bawiskar,

Could you please help me with this? I read your answers on a similar thread. Can you explain here as well according to my scenario:

AmolPawar_0-1705650049879.pngAmolPawar_1-1705650068314.png

Thanks in advance,

Amol

@Amol Pawar 

images are not visible.

what's your requirement?

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