Hide field based on a certain group - catalog item

andreea_luca
Tera Contributor

Hi,

 

How can I make a field in a catalog item visible only if the currently logged-in user is in group 'A' or 'B'? I attempted to achieve this using a UI Policy, but it wasn't successful. I've attached the script.

 

 

function onCondition() {
    if (g_user.isMemberOf("A") || g_user.isMemberOf("B")) {
        g_form.setVisible("field-name", true);
    } else {
        g_form.setVisible("field-name", false);
    }
}

 

1 ACCEPTED SOLUTION

karthiknagaramu
Kilo Sage

Hi,

isMemberOf function is part of gs api which is a server side API.

 

Please check the below community post it would be helpful.

 

https://www.servicenow.com/community/developer-forum/check-if-user-is-member-of-servicenow-group-in-...

 

Regards,

Karthik

View solution in original post

3 REPLIES 3

Gangadhar Ravi
Giga Sage
Giga Sage

try to create role and use g_user.hasRole('role_name'), make sure you are testing with non-admin user once you update the code.

AshishKM
Kilo Patron
Kilo Patron

Hi @andreea_luca , 

 

Write onLoad catalog client script and check for group membership via code which you already shared.

Let us know if it works or not. 

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

karthiknagaramu
Kilo Sage

Hi,

isMemberOf function is part of gs api which is a server side API.

 

Please check the below community post it would be helpful.

 

https://www.servicenow.com/community/developer-forum/check-if-user-is-member-of-servicenow-group-in-...

 

Regards,

Karthik