I want to pass data from client script to server script in erpnext but in ajax call i dont know the right way to give the method so the error comes Failed to get method for command frappe.api.process_fetched_data with No module named 'frappe.api'
Following is my client script
frappe.call({
method: "frappe.api.process_fetched_data", // You can call a specific server method here
args: {
//
data: date, // Send the full document or specific fields to the server script
doc: frm.doc,
},
callback: function(response) {
if (response.message) {
frappe.msgprint(response.message);
}
}
});
and where to send data means my custom server script is
@frappe.whitelist()
def process_fetched_data(data, doc):
# Parse the incoming data and document (if necessary)
data = frappe.parse_json(data)
doc = frappe.parse_json(doc)
# Perform some processing on the data
processed_data = f"Processed data: {data} from document: {doc.get('name')}"
# Return a message or further data back to the client
return {"message": processed_data}
You should not put your custom method inside frappe or erpnext app as it will create conflicts when you you try to upgrade these apps later, instead you should create your own custom frappe application and put your python function process_fetched_data
in below file,
custom_app/api.py
The AJAX Call will be
frappe.call({
method: "custom_app.api.process_fetched_data", // You can call a specific server method here
args: {
//
data: date, // Send the full document or specific fields to the server script
doc: frm.doc,
},
callback: function(response) {
if (response.message) {
frappe.msgprint(response.message);
}
}
});