Clear custom buttons in sales invoice

I am trying to remove the action buttons in the action bar in sales invoice doc form.
image

I added

onload: function (frm) {
    frm.clear_custom_buttons();
},

to my custom sales_invoice.js It works when the sales invoice form is loaded. But as soon as the customer field is filled the form refreshes and the action buttons reappear. Any ideas?

You should also try Refresh event instead of onload. I would suggest onload_post_render also.

I tried it with refresh and onload_post_render. Also I tried to add the frm.clear_custom_buttons(); function in the customer: function so that it would trigger when customer field gets filled. That all does not work. Buttons are still there.

Hello @ARAGATO did you find the solution to this problem? I’m currently facing similar issue. Any help would be greatly appreciated.

Hi, I am also facing this problem as I’m trying to remove buttons to remove unneeded functionality.

@archais Add the following code on your refresh function. The setTimeout will make sure the buttons are removed after being added by the original code to create those buttons.

setTimeout(() => {
			
			frm.remove_custom_button("Work Order", 'Create');
			frm.remove_custom_button("Project", 'Create'); 
			frm.remove_custom_button("Subscription", 'Create'); 
			
		}, 500);

That is brilliant! It worked- thanks so much. I honestly had not even thought of something like that.