Get child table data from post request

@frappe.whitelist(allow_guest=True)

def create_consumer(**args):

doc1 = frappe.new_doc("pq_consumer")

doc1.update({

        "callback_url" : (args["current_site_url"]),

        "api_key":(args["api_key"]),

        "api_secret":(args["api_secret"]),

        "user":(args["user"]),

        "consumer_doctypes": json.loads(args["consumer_doctypes"])

                             

    })

Hi @praveenkumarcse2211,

Please check the syntax with your code:

import json

@frappe.whitelist(allow_guest=True)
def create_consumer(**args):
    doc1 = frappe.new_doc("pq_consumer")
    
    # Retrieve the child table data from the POST request
    consumer_doctypes = json.loads(args["consumer_doctypes"])
    
    # Create child table entries
    for data in consumer_doctypes:
        child_table_entry = doc1.append("child_table_fieldname", {})
        child_table_entry.field1 = data["field1"]
        child_table_entry.field2 = data["field2"]
        # Set other fields as per your child table structure
    
    # Set other fields of the main document
    doc1.callback_url = args["current_site_url"]
    doc1.api_key = args["api_key"]
    doc1.api_secret = args["api_secret"]
    doc1.user = args["user"]

    # Save the document
    doc1.save()

I hope this helps.
Thank You!

3 Likes

Thanks @NCP, its working