Hide or Restrict Sidebar Options (Assigned to Tags Attachments)

i want to restircit (not hide) side bar options for specific roles
image

Reference: How to hide Toggle sidebar - #2 by NCP

Thanks for the response.
My question is that can we hide for specific users like for managers its visible and cashier its hidden?? same as role permissions.

You can set the condition according to the scenario. script will same, only put your logic.

frappe.user.has_role('Your Role')


like this

yes … !

1 Like

frappe.ui.form.on(‘’, {
onload: function(frm) {
// Roles that should not see the sidebar
let roles_to_hide_sidebar = [‘Role 1’, ‘Role 2’]; // Replace with actual role names

    // Get the current user's roles
    let user_roles = frappe.user_roles;

    // Check if the user has any of the roles in 'roles_to_hide_sidebar'
    let hide_sidebar = roles_to_hide_sidebar.some(role => user_roles.includes(role));

    if (hide_sidebar) {
        // Hide the sidebar
        hide_form_sidebar(frm);
    }
}

});

// Function to hide the form sidebar
function hide_form_sidebar(frm) {
$(frm.page.sidebar).hide();
}

This script is working