variable choice to make it visible to particular group

harinya
Tera Contributor

I have written script for variable choice to make it visible to particular group 
both scripts i have written in scoped application
when i have used same script in global it worked 
can you please help me why this is not worked in scoped application

 

this is my script include

var getUserGroup = Class.create();
getUserGroup.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    
isgroupMember: function() {
        var propertyname = this.getParameter('sysparm_propname');
        var usern = this.getParameter('sysparm_usernm');
        //gs.log('line 145' +propertyname);
        //gs.log('linev 146:' +usern);
        gs.print('line 6'+propertyname);
var groupSysId = gs.getProperty(propertyname);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', usern);
        gr.addQuery('group', groupSysId);
        gr.query();
        if (gr.next()) {
         
            return true;
        } else {
              return false;
        }
    },
    type: 'getUserGroup'
});
 
Client script:
function onLoad() {
    
    var rq =g_user.userID;
    alert(rq);
   var ga = new GlideAjax('getUserGroup');
        ga.addParam('sysparm_name''isgroupMember');
        ga.addParam('sysparm_usernm', rq);
        ga.addParam('sysparm_propname',' ''NMATeam.group.sysid');
        ga.getXML(FetchDetails);

function FetchDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true')
    {
        
        g_form.addOption('desired_service','Request an accommodation','Request an accommodation');
    }
else if (answer == 'false')
    {
    
        g_form.removeOption('desired_service','Request an accommodation','Request an accommodation');
    }
}
   
}
3 REPLIES 3

piyushsain
Tera Guru
Tera Guru

Hi, 

Can you please specify what NMATeam is and how you are dot walking it. You should use g_form to get the value of NMATeam. Also in Script Include instead of GlideRecoding the User Group membership table please use gs.getUser('user id').isMemberOf('group_name')

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Hi ,
Thanks for Response
NMA is the sys property name which is having the Group sysid, such that instead of using the group name i have used the sys property

@harinya This line 

 ga.addParam('sysparm_propname',' ''NMATeam.group.sysid');

You will not be able to work. If NMA team is a reference field, use g_form.getReference('NMATeam'); to get the reference and once you have the reference, you can apply a dot walk on the group.sys_id.

 

Hope this helps.