We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Hide Multiple Choice Field Option for Specific Users on Table Form View (not Catalog Items)

jmiskey
Kilo Sage

I feel like this should be easy, but the answer eludes me right now.  I tried searching the Community, but all the matches I found deal with Catalog Items, and I am not looking for that.  I am dealing with the Form view of a Table (so I am not in the Service Portal).

 

I have a Custom Table, and in that table, I have a Multiple Choice field that has 5 choices (options).  1 of those 5 options should ONLY be available to users have have a certain role.  So I would like to hide this choice from all users who do not have this role (on my Form).  How would I do that?

 

Thanks

1 ACCEPTED SOLUTION

Huynh Loc
Mega Sage

Hi @jmiskey ,

Use a Client Script (onLoad or onChange) to dynamically remove a specific choice from the choice list based on whether the current user has a required role.

This is the correct and supported approach for hiding individual choice values on a table form.

Example: 

 
function onLoad() {
    // Replace with your role and field name
    var requiredRole = 'x_custom.special_role';
    var fieldName = 'u_my_choice_field';
    var restrictedValue = 'restricted_option';

    // If user does NOT have the role, remove the choice
    if (!g_user.hasRole(requiredRole)) {
        g_form.removeOption(fieldName, restrictedValue);
    }
}

 

If this response was helpful, please consider marking it as Correct and Helpful. You may mark more than one reply as an accepted solution.

View solution in original post

5 REPLIES 5

@jmiskey 

Glad to help.

As per community feature you can mark multiple responses as correct.

💡 If my response helped, please mark it as correct as well so that this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader