How to connect client and server script in ERPNext

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’));

Check the video.

1 Like

Thank you for sharing the Video. I have gone through it before as well.
The issue is How to know the path of my Server file hosted in frappe cloud
That step is creating a hindrance for me
can you suggest me where to look for it or what path to specify?

Hi, Are you developing the code on the custom app or the UI?

On the UI
I am writting my codes in client and server script available in ERPNext

Please check the example:

1 Like