Hiding button using permissions

Hello;

In the Assessment Plan, there is Assessment Result button at the upper left side corner of the Assessment Plan as shown in the below image.
How I can hide it for certain user and show it for certain user using permission?
If it is like other elements in the document, I can do this using permission level (by giving it higher level value).

Below is the code that is responsible for showing this button:

    refresh: function(frm) {
            if (frm.doc.docstatus == 1) {
                    frm.add_custom_button(__("Assessment Result"), function() {
                            frappe.route_options = {
                                    assessment_plan: frm.doc.name,
                                    student_group: frm.doc.student_group
                            }
                            frappe.set_route("Form", "Assessment Result Tool");
                    });
            }
    },

Hi,
You can check frappe.user.has_role(“the role to see button”) before frm.add_button() in js. Level based permission is applied to fields I guess.
Thanks

1 Like

Do you mean we can check this by using if statement? Can you share the sample code as well?

You can put this in the if condition, with appropriate role within the quotes

if (frappe.user.has_role('System Manager') {
    // do your stuff
}
1 Like