- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2021 11:44 PM
Hi Team,
Having a requirement to write a ACL to allow only members of a particular group to edit three user defined fields in location table. Kindly suggest.
Regards,
Kayathri
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2021 08:18 AM
Hi,
so members of that group should be allowed editing only 3 fields
All others should be readonly
Do this
Display BR on your table:
g_scratchpad.isMember = gs.getUser().isMemberOf('Group Name');
onLoad Client Script:
function onLoad(){
if(g_scratchpad.isMember.toString() == 'true'){
// make all fields readonly
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
// make those 3 fields as editable
g_form.setReadOnly('fieldA', false);
g_form.setReadOnly('fieldB', false);
g_form.setReadOnly('fieldC', false);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 03:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 03:28 AM
Hi,
did you add alert what came in client script?
Did you check any UI policy etc is making those 3 fields read-only?
function onLoad(){
if(g_scratchpad.isMember.toString() == 'true'){
alert('inside if');
// make all fields readonly
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
// make those 3 fields as editable
g_form.setReadOnly('fieldA', false);
g_form.setReadOnly('fieldB', false);
g_form.setReadOnly('fieldC', false);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 04:17 AM
Hi Ankur,
There is no UI policy for these 3 fields,
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_scratchpad.isMember.toString() == 'true'){
alert('inside if');
// make all fields readonly
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
alert('inside for');
g_form.setReadOnly(fields[x], true);
}
// make those 3 fields as editable
g_form.setReadOnly('u_hot_site', false);
g_form.setReadOnly('u_hot_site_end_date', false);
g_form.setReadOnly('u_hot_site_reason', false);
}
}
Its going "inside if", but not "inside for".
Regards,
Kayathri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 04:30 AM
Hi,
I hope you are running this on native instance?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021 04:38 AM
Sorry Ankur, I haven't given the role in ACL, that was my mistake, your code is perfect.
Regards,
kayathri