Hide an option in reference field based on user role on record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 11:35 PM
Hi Team , I have a requirement to hide one option(ex: A) in reference field based on user role, for non-ITIL users option should not be visible on the form. Could you please help me on how to achieve this.
I have tried the on load script but its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 11:59 PM
HI @Anupriya_11
g_form.removeOption('field_name', 'Help'); //replace field_name with actual field name
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 12:14 AM - edited 12-16-2024 12:16 AM
hi @Anupriya_11
function onLoad() {
//Type appropriate comment here, and begin script below
var service= g_form.getValue('u_services');
var role =g_user.hasRole('itil');
if (!g_user.hasRole('itil')){
if(role == false){
alert('service'+ service);
g_form.removeOption('actual_field_backendname' ,'Help');// Replace service with actual field backend name if its OOB Service field backend name is business_service if its custom then you have something like u_service , and Help with actual option value
}
}
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:39 AM
it's a reference field so you cannot use removeOption(). it's a sysId
Can you please confirm field from where you wish to remove is a choice or reference type?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 03:29 AM
Hi @Ankur Bawiskar , Its a reference type.