Hi there,
2 questions for the price of one:
-
Could you please confirm that a child table can not be added twice in a DocType ?
I did the experience and no added line would save.
-
Let’s say I have a Doctype called Member. Let’s say I have a child table which Doctype is called Member Relative.
Its table field inside the Member Doctype is set to relative.
The Member Relative Doctype has a field called type.
How do I do to have in the relatives table all data linked to my corresponding parent but with type being filtered to something I chose?
I did many tries, unfortunately with no success.
Many thanks for your help!
Gerald
Hi,
Sorry for not being clear. So as I say to my apprentices: draw down your issue!
Here is the code I wrote down with the help of what I found on documentation and forums.
The idea is to have the child table filtered on type=‘A’
frappe.ui.form.on("Member", {
refresh: function (frm) {
frm.fields_dict['relatives'].grid.get_field('Member Relative').get_query = function(doc, cdt, cdn) {
return {
"filters": {
"type": 'A'
}
}
}
}
})
I think the problem is with the field name you use the field label: member_relative
frm.fields_dict[‘relatives’].grid.get_field(‘Member Relative’).get_query
Thanks, unfortunately, it does not work either.
I have also tried what is proposed in the doc
https://frappeframework.com/docs/user/en/api/form
// set filters for Link field item_code in
// items field which is a Child Table
frm.set_query('item_code', 'items', () => {
return {
filters: {
item_group: 'Products'
}
}
})
With that code:
frappe.ui.form.on('Member', {
onload: function(frm) {
console.log('onload');
frm.set_query('Member Relative', 'relative', () => {
return {
filters: {
type: 'A'
}
};
});
}
})
Unfortunately it does not work either.