I am working on an instance of ERPnext that I have hosted in frappe cloud and I am stuck how to connect the client and server script.
Everytime I try to have that I encounter an error. I am attching the code for your reference. Please reply if you know the solution as I am stuck in this situtaion…
SERVER SCRIPT:
def cancel_delivery_order(delivery_order_name):
try:
doc = frappe.get_doc(“Delivery Order”, delivery_order_name)
if doc.docstatus == 1:
doc.cancel()
return {“status”: “success”, “message”: “Delivery Order has been cancelled”}
else:
return {“status”: “failed”, “message”: “Only submitted documents can be cancelled”}
except Exception as e:
return {“status”: “error”, “message”: str(e)}
CLIENT SCRIPT:
frm.add_custom_button(__(‘Cancel’), function() {
frappe.confirm(
(‘Are you sure you want to cancel this Delivery Order?’),
function() {
frappe.call({
method: ‘sgnirman.api.cancel_delivery_order’,
args: {
delivery_order_name: frm.doc.name
},
callback: function(r) {
if (!r.exc && r.message.status === ‘success’) {
frm.reload_doc();
frappe.msgprint((‘Delivery Order has been cancelled.’));
} else {
frappe.msgprint({
title: __(‘Error’),
indicator: ‘red’,
message: r.message.message
});
}
}
});
}
);
}, __(‘Actions’));