我想在 erpnext 中将数据从客户端脚本传递到服务器脚本,但在 ajax 调用中我不知道给出该方法的正确方法,因此出现错误无法获取命令 frappe.api.process_fetched_data 的方法,没有名为“frappe”的模块.api'
以下是我的客户端脚本
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);
}
}
});
发送数据的位置意味着我的自定义服务器脚本是
@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}
您不应该将自定义方法放入 frappe 或 erpnext 应用程序中,因为当您稍后尝试升级这些应用程序时,它会产生冲突,相反,您应该创建自己的自定义 frappe 应用程序并将您的 python 函数
process_fetched_data
放在下面的文件中,
custom_app/api.py
AJAX 调用将是
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);
}
}
});
```