Add Custom bottom disappears

Why when adding a custom button it disappears on Sales Order ?

erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
	refresh: function(doc, cdt, cdn){
	if (this.cur_frm.doc.docstatus===0) {
		cur_frm.add_custom_button(__("Taxa Cambio"), function() {

I have tried when customer (frappe.ui.form.on(“Sales Order”,“customer”, function(frm,cdt,cdn)) selected and I can see that button for one second and afterwards is gone …


I presume that you want to add button to Sales Order for executing some custom business logic, in such case you need to add code as follows,

frappe.ui.form.on('Sales Order',
   refresh: function(frm) {
         frm.add_custom_button(__("button_name"), function() {
             //add your logic
     }, __("group_name"));

Moreover code must be added in sales_order.js, and not in Selling Controller.

This is standard practice while we add buttons to any form.

if (doc.docstatus===0) {

Also it will appear only for not saved SO because of docstatus condition.

@shreyasp thanks for the tips.

@KanchanChauhan I have tried like if (this.doc.docstatus ===0) returns Unable to get property ‘docstatus’ of undefined or null reference

and if I try if (doc.docsstatus === 0 ) returns DOC undefined …


The wrong spell was only here on the code is correct.
But thanks for the tip as I believe is better to have a button near the field I need the result and enabled/visabled when docstatus ===0 :slight_smile: