How to Check Role in client script

In Python.

roles = frappe.get_roles(frappe.session.user)
print(roles)
if "Rom_DM_Role" in roles:
   category_name = 'Dining'
if "Rom_Chef_Role" in roles:
   category_name = 'Kitchen'

in Javascript

let role_avail = frappe.user_roles.includes("System Manager")

or

if (frappe.user.has_role("Role Name")) {
    console.log("The current user has the specified role.");
} else {
    console.log("The current user does not have the specified role.");
}

I hope this might be helpful to you.
Reference

1 Like