Hello,
I am using the function frappe.get_list to get all the child table records of my custom DocType My Work Order. The child table name is My Work Order Operations.
The number of rows returned are identical but the fields of each row are blank without data.
Why?
TIA
Yogi Yang
peterg
October 8, 2022, 7:45am
2
Can you share the code you’re using? JS or Python? (If it’s Python, I believe you need to use get_all to poll child tables directly)
Hello @peterg
Here is the Python code.
my_work_order = frappe.get_doc("My Work Order", my_work_order)
# Get the Processes from Work Order
my_work_order_processes = frappe.get_list("My Work Order Operations", {"parent": my_work_order.name})
my_route_card = frappe.new_doc("My Route Card")
my_route_card.date = datetime.datetime.now()
my_route_card.my_work_order_num = my_work_order.name
my_route_card.customer_code = my_work_order.customer_code
my_route_card.item_to_mfg = my_work_order.production_item
my_route_card.qty = my_work_order.qty
for spc in my_work_order_processes:
my_route_card.append("operations",{
"operation": spc.operation,
"workstation": spc.workstation,
"source_warehouse": spc.source_warehouse,
"target_warehouse": spc.target_warehouse,
"perform_qc": spc.perform_qc,
"time_in_mins": spc.time_in_mins,
"quality_inspection_template": spc.quality_inspection_template
})
my_route_card.flags.ignore_permissions = 1
my_route_card.flags.ignore_mandatory = 1
my_route_card.save()
frappe.db.commit()
TIA
Yogi Yang
peterg
October 8, 2022, 10:36am
4
Did you try with get_all?
Hello,
I have not tried that. Will give it a try and update you here.
TIA
Yogi Yang
Hello @peterg ,
To update you get_all is not working for me.
Calling the function does not generate any errors but I am not able to iterate through all the rows.
TIA
Yogi Yang
peterg
October 10, 2022, 6:35am
7
You have to identify the fields you want pulled. get_all and get_list return the name only by default. fields=['*'] will pull everything.
Hello @YogiYang ,
why not use my_work_order.fieldname_of_child (it’s a list contain all children) if you already use get_doc
1 Like
Hello,
I don’t understand as to how I can iterate through each items if I use get_doc?
Can you provide me with a sample to follow?
TIA
Yogi Yang
Hello @peterg ,
Yes, this works!!
Thanks a lot. Actually as this was not working for me I had resorted to using SQL query. But now I will convert to using get_all.
TIA
Yogi Yang
peterg
October 10, 2022, 7:50am
11
look at your my_work_order variable in the console. It will have a property called “operations” (or whatever you named the child table field). This property will contain all of the data you want. No need for a separate get_list/get_all operation.
3 Likes