How to hide the primary button in listview

Hi

I want to hide the primary action button in listview for doc Sales Order. How can I make it?image
Like the snapshot shows above, i’d like to hide button +Add Sales Order.

Thanks.

2 Likes

I’m assuming this change is needed for specific users ?
Then look at Role Permissions Manager to define who can create\add Sales Orders.

Hi @msalim79

My goal is let people create sales order from quotation instead of click add sales order directly.
So I just want to hide it.

Thanks.

After googled a lot. I found the solution
In my custom script of that doctype listview, add
$(‘.btn-primary’).hide(); in onload: function(listview){}

4 Likes

Hi, I put that code in my file lease_contract_list.js with the following code but it’s not working.

frappe.listview_settings[‘Lease Contract’] = {
(‘.btn-primary’).hide(); in onload: function(listview){}
}

You need to add it in Client Script

https://docs.erpnext.com/docs/v13/user/manual/en/customize-erpnext/client-scripts

1 Like

Thanks for the reply. I copied the code exactly but get a red cross with the error “Expected identifier and instead saw ‘in’.” I’ve tried multiple variations and I have also tried from list.js but to no avail.

Hi @gudiva,

Please apply it.

frappe.listview_settings['Lease Contract'].refresh = function(listview) {
	$('.btn-primary').hide();
};

Then reload and check it.

Thanks.

1 Like

Thanks @NCP but when I try that I just get a blank page

I tried this code and removed the button in the middle of the page, but the top right hand button still persists

frappe.listview_settings[‘Lease Contract’] = {
onload: function(listview) {
(‘.btn-primary’).hide();
}
};

It’s working on my side version 13.

@NCP thank you for your efforts.

What I have noticed is that the code does work on core doctypes but not those created from custom apps, which is what I was trying to do in my case. I created and tried the code on a new vanilla custom app and still the problem persists. I don’t know if this problem is inherent but I’ll try to debug and post my findings. Cheers guys

Is it possible to do it via custom app rather than desk?

Hi @Niraj_Gautam,

Yes,

add in custom app hook.py

doctype_list_js = {"Your DocType" : "public/js/your_doctype_list.js"}

Go to the custom_app/public/js/ path and create a your_doctype_list.js
and add your code according.

Reload/Restart/Migrate the site and check it.

Thank You!

Thank you. But this is not reflecting any changes.

You can override the button’s function using the client script.
See sample code below.

frappe.listview_settings['Sales Order'] = {
    primary_action() {
        frappe.msgprint(__('Create the Sales Order under its Project.'));
        return false;
    }
}

Good luck!

1 Like

Scenario:
In the HelpDesk tickets (Url :http://mysite.localhost:8000/helpdesk/tickets). Now I want to hide this primary button from my custom app.

  • Above solutions are not working for me.
    Thank you