- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2017 12:18 PM
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
}
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2017 05:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2017 05:16 AM
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
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2017 05:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2017 01:43 PM
Thanks Ravesh, just did a ui policy and it was less headache..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 06:24 AM - edited ‎03-22-2023 06:27 AM
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