Hi all,
I have added custom Get Items from button. I use example from here:
and it is helpful and its working. thankyou
But I want to add filter so the list can filter out SDN only
My code :
function get_items_from_sdn(delivery_note) {
frappe.call({
"method": "frappe.client.get_list",
"args": {
"doctype": "Delivery Note",
"name": delivery_note,
"filters": {
"naming_series": "SDN-.YYYY.-"
}
},
i also referred to here as well : Frappe Ajax Call but still unable to get the result. Can suggest/point out at which line should I fix the code ?
Abdeali
2
Do like this:
function get_items_from_sdn(delivery_note) {
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Delivery Note",
filters: {
naming_series: "SDN-.YYYY.-",
},
fields: ["name", ITEM_FIELD_NAME],
},
});
}
1 Like
Thankyou @Abdeali , I did as per advise and below is the complete code:
frappe.ui.form.on('Project', {
refresh: function(frm) {
frm.add_custom_button(__("Get items from"), function() {
show_sdn_dialog(frm);
});
}
});
function show_sdn_dialog(frm) {
frappe.prompt([
{'fieldname': 'delivery_note', 'fieldtype': 'Link', 'label': 'Delivery Note', 'reqd': 0, 'options': 'Delivery Note'}
],
function(delivery_note){
console.log(delivery_note.delivery_note);
get_items_from_sdn(delivery_note.delivery_note);
},
'Get items from Delivery Note',
'Get it'
);
}
function get_items_from_sdn(delivery_note) {
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Delivery Note",
name: delivery_note,
filters: {naming_series: "SDN-.YYYY.-"}
},
callback: function(response) {
// add items to child table
var sdn = response.message;
sdn.items.forEach(function (item) {
var child = cur_frm.add_child('item_details');
frappe.model.set_value(child.doctype, child.name, 'item_code', item.item_code);
frappe.model.set_value(child.doctype, child.name, 'item_name', item.item_name);
frappe.model.set_value(child.doctype, child.name, 'brand', item.brand);
frappe.model.set_value(child.doctype, child.name, 'item_group', item.item_group);
});
cur_frm.refresh_field('item_details');
}
});
}
but still same, unable to filter the list with SDN only
2nd, I notice if I use frappe.client.get_list, I am unable to retrieved the item from Delivery Note into Project:
but if I use frappe.client.get, then it works.
Seeking advises at which line should I fix the code ?
Abdeali
4
get_list
checks permission, so check your role and permission.
Try with get_all
.
and your args
are incorrect.
see:
1 Like
Thankyou very much @Abdeali , it is helpful and informative
I able to solved it, thank you for your time and guidance
attached is the code for reference :
function show_sdn_dialog(frm) {
frappe.prompt([
{'fieldname': 'delivery_note', 'fieldtype': 'Link', 'label': 'Delivery Note', 'reqd': 0, 'options': 'Delivery Note',
'filters': {naming_series: "SDN-.YYYY.-", status: ["!=", "Cancelled"] , docstatus: ["!=", 2]}
}
],
the filters should be in frappe.prompt
instead of arg
Thankyou once again. Cheers
1 Like