We have an issue in passing an array from the client side script to the frappe server.
On the server, we have added to erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py at the end
@frappe.whitelist()
def count_fruit(fruit):
_count = 0;
for f in fruit:
_count = _count + 1
return { 'Count': _count }
From the client side, we then execute this through a custom script on Sales Invoice
// count fruit
frappe.ui.form.on("Sales Invoice", {
refresh: function(frm) {
var fruit = ["Orange", "Banana", "Lemon"];
frappe.call({
// type: 'POST',
method: 'erpnext.accounts.doctype.sales_invoice.sales_invoice.count_fruit',
args: { 'fruit': fruit },
callback: function(r) {
if (!r.exc) {
frappe.msgprint("Number of fruit: " + r.message.Count);
}
}
});
}
});
Now, we want the fruit (or in fact the sales invoice items, just simplified to illustrate the problem; that was not a problem) to be passed as an array.
Actual result:
- number of fruit 27 (which is the number of characters in the string)
Expected results
- number of fruit 3 (number of elements in the array
So the issue is that the parameter is passed as a string rather than an array. How can we pass the array as an array (and not as a string)?