- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2020 07:46 AM
Hi,
I have 10 sections inside a form that I want to make READONLY (I must not hide the section) for some users with a specific role only.
For example: I have UserA with role A: he can only edit section 1,2,3,4,5 but the rest will be readonly for him
But for UserB with roleB, he can edit sections 1,2,3 and the rest will be readonly, etc you get the idea
I know I cannot use UI policy to do this for the whole section but for fields only. The thing is: the sections have over 100 fields each.
Can I use ACL* for this? if yes how?
Can I use a client script. In this case I have to run g_form.setReadOnly() on all the fields.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2020 07:52 AM
Hi,
Unfortunately, an ACL won't assist here. There isn't a way to easily make an entire section read-only.
You'd have to use a client script and grab their role using something like:
g_user.hasRole('itil') and go from there.
Keep in mind, any fields that are mandatory and are exposed on load, won't be able to be read-only (I believe).
So you'd have to balance the mandatory requirements as well. May take some work there.
So you'd want to check their role, setMandatory false, then readOnly true...etc.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2020 07:52 AM
ACL is the best way to do it.
But you would have to create as many ACL's depending on how many fields you have in that section.
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 03:59 AM
Hi,
I’ve seen that if you create a client script, loop through all the variables in the section, and then set them to read-only, it seems to work.
Client script (onLoad):
var ga = new GlideAjax('XXXXXXXX');
ga.addParam('sysparm_name', 'getVariableSection');
ga.getXML(setReadOnlyVarSection);
function setReadOnlyVarSection(response) {
//var variablesArray = JSON.parse(answer);
var answer = response.responseXML.documentElement.getAttribute("answer");
var variablesArray = JSON.parse(answer);
g_form.addInfoMessage(answer);
g_form.addInfoMessage(variablesArray);
variablesArray.forEach(function(varName) {
g_form.setReadOnly(varName, true);
});
}
Script include:
getVariableSection: function() {
var variables = [];
var grSUE = new GlideRecord('sys_ui_element');
grSUE.addEncodedQuery("sys_ui_section=XXXXXXXXXX^element!=.split^ORelement=NULL^element!=.end_split^ORelement=NULL^element!=.begin_split^ORelement=NULL");
grSUE.query();
while (grSUE.next()) {
variables.push(grSUE.getValue('element'));
}
return JSON.stringify(variables);
},