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

Mike Allen
Mega Sage

Just curious, why no ACL?   That is what they are there for.


I was advised not to use it.. Would you recommend to do so? If yes, how?


Just put a read ACL on the field.   In the script portion, say something like:



if(gs.getUser().isMemberOf('Database')){


answer = true;


}else{


answer = false;


}


KB15
Giga Guru

I think ACLs might be the better option though it'd have to be roles based and then assign the role to those groups.


Elevate your security rights and right click on the field you want to change the security to like so:



find_real_file.png



Select the operation and the role you want to have the ability to read.