Restrict field to members of certain groups

snserge
Kilo Contributor

Hi guys,

Need a bit of help restricting a newly created field to be seen by members of 7 different user groups.

I don't want to go through ACL so I did a Client script and a script include:

The field gets hidden to everybody

Any advice?

Client Script:

function onLoad() {

//Type appropriate comment here, and begin script below

var ga = new GlideAjax('script_include_name');

ga.addParam('sysparm_name','Restrict_type_of_inc');

ga.getXML(SetVisibility);

function SetVisibility(response) {

var answer = response.responseXML.documentElement.getAttribute("answer") == "true";

g_form.setVisible("variable_name", answer);

}

}

Script Include:

var script_include_name   = Class.create();

script_include_name.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  script_include_name: function() {

        return gs.getUser().isMemberOf('group name here');

    },

    _privateFunction: function() { // this function is not client callable

    }  

});

1 ACCEPTED SOLUTION

Rajesh Mushke
Mega Sage
Mega Sage

i think there is no use of script include and client script, for field hiding simply you can acheive this by using UI Policy.




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

View solution in original post

8 REPLIES 8

Chandu Telu
Tera Guru
Tera Guru

Hi Serge,


Check below code it may help you




Check the answer true/false by adding the alert





Check the script include called by function adding gs.log




Client Script:


function onLoad() {


//Type appropriate comment here, and begin script below


var ga = new GlideAjax('script_include_name');


ga.addParam('sysparm_name','Restrict_type_of_inc');


ga.getXML(SetVisibility);



function SetVisibility(response) {


var answer = response.responseXML.documentElement.getAttribute("answer")


g_form.setVisible("variable_name", answer);


}


}



Script Include:


var script_include_name   = Class.create();


script_include_name.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  sysparm_name: function() {


        return gs.getUser().isMemberOf('group name here');


    },


    _privateFunction: function() { // this function is not client callable


    }


});




Rajesh Mushke
Mega Sage
Mega Sage

i think there is no use of script include and client script, for field hiding simply you can acheive this by using UI Policy.




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Thanks Ravesh, just did a ui policy and it was less headache..


Hello,

 

I am trying to do the same thing and I have a question:

 

I guess it is not possible to use gs API in UI Policy as it is client side.
So how did you manage to apply following code on UI Policy:

 

gs.getUser().isMemberOf('group name here');

 

 

Thank you very much in advance for your feedback !

 

Kr,

Sylvain