Hi All,
I am trying to clear the child table records from Sales Order Items.
Below is my code which I am running on a button press via server side script, but it is not removing the records from the child table.
@frappe.whitelist()
def get_items_from_product_powerplay(doc, qty,method=None):
if isinstance(doc, basestring):
doc = frappe.get_doc(json.loads(doc))
doc.items = []
I appreciate if anyone can help me regarding the same.
Regards
Ruchin Sharma
Hi @ruchin78
try below code
parent_doc = frappe.get_doc('DocType', docname)
parent_doc.set('child_table_name', [])
Thanks, Rohit
4 Likes
@rohit_w
@makarand_b
I have tried but its not working.
Regards
Ruchin Sharma
@ruchin78 ,
did you save the doc after setting the items
to []
?
Thanks
1 Like
@makarand_b
No, I didn’t save it. I wanted to delete it before saving.
Hi @ruchin78 ,
try this one,
doc.set(“items”, [])
refresh_field(“items”)
Hi All,
I am still on the same page. I appreciate if anyone can help me on the same.
Regards
Ruchin Sharma
Hi,
I am not able to clear child table records based on a condition earlier in version 6 the code was working perfectly but now, its not working. Below is my code for the same.
while (i–)
{
if(tbl[i].product_type == “PV/VIDEO - BMT”)
{
cur_frm.get_field(“items”).grid.grid_rows[i].remove()
}
}
I appreciate if anyone can help me in this context.
This code was working and earlier and below is post from where it got resolved.
Here is my shot at it. I strongly believe that the solution is to parse the array from the last to the first element. In this way, the array elements that get re-indexed will not affect the behavior:
var tbl = doc.child_table || [];
var i = tbl.length;
while (i--)
{
if(tbl[i].field_name == '')
{
cur_frm.get_field("child_table").grid.grid_rows[i].remove();
}
}
cur_frm.refresh();
Give it a try
@sorin.negulescu
@Nishant_Jariwala
Any idea why it is not working now?
Regards
Ruchin Sharma
@ruchin78 ,
for js try cur_frm.clear_table(table_fieldname)
for py refer to [quote=“rohit_w, post:2, topic:14624”]
parent_doc = frappe.get_doc(‘DocType’, docname)
parent_doc.set(‘child_table_name’, [])
[/quote]
Thanks
@makarand_b
I tried
frappe.ui.form.on("Sales Order", "onload", function(frm, doctype, name){
cur_frm.clear_table(items);
});
But it is giving me below error on console:
ReferenceError: items is not defined
Regards
Ruchin Sharma
1 Like
it should be cur_frm.clear_table("items");
then refresh fields using cur_frm.refresh_fields();
5 Likes
@makarand_b
My bad, what a silly mistake I did.
Anyways thanks for your quick response, its working now.
Regards
Ruchin Sharma