Error to cancel document frappe.call method

Hello,

I am writing client script to cancel a document (A-2024-001) of “Doctype B” from a custom button on form view of “Doctype A”.

Below is the part of my script.

frappe.db.get_doc('Doctype B', 'A-2024-001')
                                .then(doc => {
                                    // console.log(doc)
                                    frappe.call({
                                        method: "frappe.client.cancel",
                                        args: {
                                            "doctype": doc.doctype,
                                            "docname": doc.name,
                                            "doc": doc
                                        },
                                    });
                                })

but its giving error as below.

TypeError: cancel() missing 1 required positional argument: 'name'

Any hint and suggestions will be highly appreciated.
Thanks.

Found the Solution.

frappe.db.get_doc('Additional Salary', emi[i][0])
                                .then(doc => {
                                    // console.log(doc)
                                    // console.log(doc.name)
                                    // console.log(doc.doctype)
                                    frappe.call({
                                        method: "frappe.client.cancel",
                                        args: {
                                            "doctype": doc.doctype,
                                            "name": doc.name,
                                        },
                                    });
                                })

Now I am able to Cancel the Document.
Thanks.

Hi @umarless,

Please review the syntax code, and I’ve tested it, and it functions correctly.

frappe.ui.form.on('Doctype A', {
    refresh: function(frm) {
        frm.add_custom_button(__('Cancel Document B'), function() {
            cancelDocumentB(frm);
        });
    }
});

function cancelDocumentB(frm) {
    var documentName = "A-2024-001";

    frappe.call({
        method: "frappe.client.cancel",
        args: {
            "doctype": "Doctype B",
            "name": documentName
        },
        callback: function(response) {
            if (response.message) {
                frappe.msgprint("Document B cancelled successfully.");
            } else {
                frappe.msgprint("Failed to cancel Document B.");
            }
        }
    });
}

Thank You!

1 Like