ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Eval:frappe.user.has_role not working


#1

Hi all, i am working on to display the button for particular user only i.e ‘QA Manager’ i have given eval:frappe.user.has_role(‘QA Manager’) && doc.pending_qa_approval == 1 for the stp field which datatype has ‘button’…but the ‘stp button’ is not visible for the ‘QA Manager’ is anything i missed out in eval?


#2

Not sure whether it will work or not but

frappe.user_roles[1]

gives current logged in user’s role in console . You can try with that, just change the array where your desired role is mentioned.

Hope this will work


#3

sorry, @nikzz i can’t get your point can u explain it. How can i give current logged in user role in console? I want the ‘stp’ button automatically has to be display when i opened the ‘QT’ record
(login as ‘QA Manager’ )


#4
console.log(frappe.user_roles)

This will give all roles in an array in console, in array form. Just use the index of the role you want as, let say QA Manager lies at 41’th index . So use,

console.log(frappe.user_roles[41])

#5

I’m not sure how well this code works in eval or rather I’d say I have no documented examples if such a thing works but why not put this in Custom JS ? That would be straightforward.

doc.pending_qa_approval == 1

This can stay in eval.

Restrict this field’s Perm level say to 1. Then in Role Permissions Manager, allow QA Manager to edit fields with permlevel 1


#6

hi @root13F i tried this role permission but button is not visible in ‘QA Manager’ even if there is no display depends on condition also button is not visible in ‘QA Manager’ except that ‘stp’ button field all other fields are displayed in ‘QA manager’…how can this done in custom js?


#7

In refresh event try this line of code :

cur_frm.toggle_display('stp', frappe.user.has_role(""QA Manager))

Later on check from both users - Non QA manager and QA Manager

Edit : Also hide this field via the docfield properties.


#8

hi @root13F i tried but not worked so i made the button has custom button and wrote user role validation in js.


#9

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)