- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 05:53 AM
Hello all,
I am looking for a way, if there's any, to have the options in a select box be selectable by role.
As shown in he attachment, I would like for only users with certain role OR group membership to ONLY be able to select (or see) the Purchase option.
Any help or suggestion would be appreciated.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:34 AM
Hey,
it should be like this
function onLoad() {
if (!g_user.hasRole('rtls_purchase_view')) {
g_form.removeOption('type_of_purchase_replacement',"Purchase");
}
}
, also remove <>, those are just to show where you have to place the fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:34 AM
Hey,
it should be like this
function onLoad() {
if (!g_user.hasRole('rtls_purchase_view')) {
g_form.removeOption('type_of_purchase_replacement',"Purchase");
}
}
, also remove <>, those are just to show where you have to place the fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:04 AM
Hi @Hola Ola ,
you can write a script to check if the user is holding that particular role then should be able to see the option else use the removeOption for removing the Purchase option from dropdown list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:06 AM
Hi @Hola Ola,
This is easily achieved by using a Client Script and check if the logged in user has the role (or is a member of the group).
I've provided a link to the ServiceNow docs which go into more details, but essentially the g_user API is available from Client Scripts and you leverage the following method:
if (!g_user.hasRoleExactly('the_role_name_required')) {
g_form.removeOption('the_field_name', 'the_value_name_to_remove');
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
Here's the SN link: https://developer.servicenow.com/dev.do#!/learn/courses/washingtondc/app_store_learnv2_scripting_was...