Add condition to UI Policy to check if user who is logged in has role 'admin'

Kasia5
Tera Contributor

Hi All!

 

I have a Catalog UI Policy which make one field in INC form read only.

I want to add condition to check if currently logged in user has role 'admin' to exclude this users to make them able to change this field if it will be needed.

So condition will sth like: if user has not role admin then make field read only.

How can I achieve this?

6 REPLIES 6

Aniket Chavan
Tera Sage
Tera Sage

Hello @Kasia5 ,

I assume you might be using table level UI policy and not the catalog UI policy, and Yes you can simply achieve this by using the script below in advance run script section.

 

function onCondition() {
    if (!g_user.hasRole('admin')) {
        g_form.setReadonly('fieldname', true); // Set field readonly
    }
}

AniketChavan_0-1705052037815.png

 

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,
Aniket

Aniket Chavan
Tera Sage
Tera Sage

Hello @Kasia5 

I wanted to check in regarding the response I provided. If my suggestions were beneficial in addressing your query or helped in resolving your issue, would you mind marking it as helpful, accepting the solution, and closing the thread? Your acknowledgment not only shows appreciation for the assistance but also assists future readers who might come across a similar problem.

Thank you for your consideration!

Best regards,
Aniket.