Update status for sales invoice

i added new tab break (sales survey) include field count_invoice field , the purpose is to make survey after sales invoice done i make count_invoice field property allow on submit but when i make survey after auto update count_invoice field the status all old sales invoices appearing UPDATE Status i want ignore this Update button apper

i use this Clint script code to get count invoice onload event


frappe.ui.form.on('Sales Invoice', {
    customer: function(frm) {
        // fetch the total count of invoices for the customer
        frappe.call({
            method: 'frappe.client.get_list',
            args: {
                doctype: 'Sales Invoice',
                fields: ['name'],
                filters: {
                    'customer': frm.doc.customer,
                    'status': ['not in', ['Cancelled', 'Draft']]
                },
                limit_page_length: 9999 // Set a high limit to fetch all invoices
            },
            callback: function(r) {
                if (r.message) {
                    // Update the custom_invoice_count field in the Sales Invoice form
                    frm.set_value('custom_invoice_count', r.message.length);
                }
            }
        });

        // fetch the count of custom_call_made where type is checked for the customer
        frappe.call({
            method: 'frappe.client.get_list',
            args: {
                doctype: 'Sales Invoice',
                fields: ['name'],
                filters: {
                    'customer': frm.doc.customer,
                    'custom_contact_made': 1, // Assuming custom_call_made is a checkbox field
                    'status': ['not in', ['Cancelled', 'Draft']]
                },
                limit_page_length: 9999 // Set a high limit to fetch all invoices
            },
            callback: function(r) {
                if (r.message) {
                    // Update the custom_call_made_no field in the Sales Invoice form
                    frm.set_value('custom_contact_made_no', r.message.length);
                }
            }
        });
    },
    onload: function(frm) {
        // fetch all sales invoices for the current customer on form load
        if (frm.doc.customer) {
            frappe.call({
                method: 'frappe.client.get_list',
                args: {
                    doctype: 'Sales Invoice',
                    fields: ['name'],
                    filters: {
                        'customer': frm.doc.customer,
                        'status': ['not in', ['Cancelled', 'Draft']]
                    },
                    limit_page_length: 9999 // Set a high limit to fetch all invoices
                },
                callback: function(r) {
                    if (r.message) {
                        // Update the custom_invoice_count field in the Sales Invoice form
                        frm.set_value('custom_invoice_count', r.message.length);
                    }
                }
            });

            // fetch the count of custom_call_made where type is checked for the customer
            frappe.call({
                method: 'frappe.client.get_list',
                args: {
                    doctype: 'Sales Invoice',
                    fields: ['name'],
                    filters: {
                        'customer': frm.doc.customer,
                        'custom_contact_made': 1, // Assuming custom_call_made is a checkbox field
                        'status': ['not in', ['Cancelled', 'Draft']]
                    },
                    limit_page_length: 9999 // Set a high limit to fetch all invoices
                },
                callback: function(r) {
                    if (r.message) {
                        // Update the custom_call_made_no field in the Sales Invoice form
                        frm.set_value('custom_contact_made_no', r.message.length);
                    }
                }
            });
        }
    }
});

is there any help?

When you change the values “on load,” they aren’t being saved, which is why the Update button appears.
You’ll need to add frm.save(‘Update’); after modifying the field values to ensure they’re saved properly.

can i bring count invoice for the current customer when i make first crate for invoice in the beginning only

Do you require the count at the moment of creating the invoice, or is it needed after the creation or submission?

Additionally, should the current invoice be included in the count or not?

yes the count at the moment of creating the invoice,

and the current invoice be included in the count