How to get the child table values

Hi,
How can I get the values from child table and used them in python side?
Any ideas?

Hi @Ra.st

You can get child table values from sql query or for loop conditions

ex:
frappe.db.sql(
“”“select parent,salary_component,amount,year_to_date from {0}.tabSalary Detail where parent = ‘{1}’”“”
.format(current_db_name, payslip.name), as_dict=True)

You mean I have to take the values in .js then pass it to python right?

Yes , if you need js you can use like this
for (var i = 0; i < frm.doc.child_table_name.length; i++) {
if (frm.doc.child_table_name.child_field){
}
}

How can I sent all the values to python without specify the .child_field? any ideas? I’m new on frappe:)

Thank you.

Any trigger function or validate or onload or submit function?
Please tell me where you need js or python?

I want to get the values from the child table in python if it’s work.
but my question I want to have the perfect way to get the values from child table to use it in code
Is it js or python?

Hi, @Ra.st

I believe the below code is your requirement

import frappe

# Connect to the Frappe database
frappe.connect()

# Query the child table
parent_docname = "DOC-001"
result = frappe.db.sql('SELECT * FROM `tabChildTable` WHERE parent = %s', (parent_docname,))

# Retrieve the data
data = frappe.as_dict(result)

# Process the data
for row in data:
    # Do something with each row
    print(row)

# Disconnect from the database
frappe.db.close()

Hope this will help you out.
Thank you

Yes! I think it will work! but now the Child table doesn’t appear while I’m printing all the fields on the parent table , so when I try to write tabitems which is the child table it shows this error::: ( Table ‘_b3ee5baedc928263.tabitems’ doesn’t exist )