How can I add a single child table to two doc fields in the same doctype?

I have two docfields of type ‘Table’ and both contain same types of data.
Now I created one child table and want to assign this to both of my docfields in the main doctype.

But when I am doing it, it is not working. It doesn’t show any error, but when trying to save fields, it is not saving anything.

Any help on this?

Any help on this?

@Abhiraj_Tulsyan can you please share meta for your doctype?

Share meta as in?

{{host}}/api/method/get_meta?doctype={Your doctype name}
run this is browser where you are logged in.

I am getting error on it:

Traceback (most recent call last):
  File "apps/frappe/frappe/handler.py", line 74, in execute_cmd
    method = get_attr(cmd)
  File "apps/frappe/frappe/handler.py", line 289, in get_attr
    method = globals()[cmd]
KeyError: 'get_meta'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 76, in execute_cmd
    frappe.throw(_("Failed to get method for command {0} with {1}").format(cmd, e))
  File "apps/frappe/frappe/__init__.py", line 603, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 575, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 526, in _raise_exception
    raise exc
frappe.exceptions.ValidationError: Failed to get method for command ge

version?

Version 15

@hemant.tripathi
Any other info required?

Actully i want the fields present in your doctype along with thier child tables so that i can write js script for field data filling

Can you tell me exactly what you want to achieve by coding. I can code that myself but if you can tell exactly what you want to do?

Here is my freightjob.json file

{
 "actions": [],
 "autoname": "autoincrement",
 "creation": "2023-12-29 21:57:56.583402",
 "doctype": "DocType",
 "engine": "InnoDB",
 "field_order": [
  "section_break_bed1",
  "freight_rfq",
  "pol",
  "incoterm",
  "shipping_order",
  "transportation_by",
  "liner_name",
  "total_number_of_packages",
  "gross_weight",
  "volume",
  "invoice_number",
  "invoice_value",
  "net_weight",
  "column_break_lmfl",
  "customer",
  "pod",
  "service_type",
  "package_mode",
  "cfs_supplier",
  "cfs_code",
  "vessel_name",
  "voyage_number",
  "freight_charge_type",
  "eta",
  "ata",
  "good_description_section",
  "freight_items",
  "section_break_ywjf",
  "fcl_package",
  "section_break_ywtr",
  "lcl_package",
  "master_bl_details_section",
  "mbl_number",
  "master_bl_consignee",
  "column_break_bate",
  "master_bl_shipper",
  "master_bl_notifyparty",
  "house_bl_details_section",
  "house_bl_shipper",
  "house_bl_notifyparty",
  "column_break_xmip",
  "hbl_number",
  "house_bl_consignee",
  "igm_details_section",
  "igm_filing_date",
  "igm_inward_date",
  "igm_number",
  "section_break_ftkc",
  "containers",
  "scope_of_work_section",
  "local_flow",
  "column_break_aevp",
  "freight_flow",
  "column_break_wihm",
  "destination_flow",
  "section_break_urln",
  "sa_service_type",
  "description_section",
  "description",
  "po_pricing_tab",
  "po_item",
  "total_po",
  "so_item",
  "total_so",
  "workflow_tab",
  "workflow_history",
  "documents_tab",
  "workflow_state",
  "section_break_dqvc",
  "document_list",
  "tab_5_tab",
  "do_free_days",
  "empty_return_date",
  "vessel_unloading_date",
  "do_obtained_date",
  "ooc_number",
  "ooc_date",
  "column_break_qerr",
  "do_valid_till",
  "do_status",
  "do_extended_days",
  "port_movement_date",
  "boe_tab",
  "assessable_value",
  "boe_date",
  "boe_status",
  "assessment_date",
  "boe_number",
  "column_break_troy",
  "boe_type",
  "examination_date",
  "duty_value",
  "number_of_queries",
  "examination_mark",
  "transport_tab",
  "transport_containers",
  "other_tab",
  "telex_release",
  "ssr_status",
  "form_13_release_date",
  "cfs__hbl_manifest_tab",
  "hbl_manifestation_status",
  "column_break_fdzf",
  "cfs_nomination_status"
 ],
 "fields": [
  {
   "fieldname": "section_break_bed1",
   "fieldtype": "Section Break"
  },
  {
   "fieldname": "igm_number",
   "fieldtype": "Data",
   "label": "IGM Number"
  },
  {
   "fieldname": "pol",
   "fieldtype": "Link",
   "label": "POL",
   "options": "Ports"
  },
  {
   "fieldname": "pod",
   "fieldtype": "Link",
   "label": "POD",
   "options": "Ports"
  },
  {
   "fieldname": "freight_rfq",
   "fieldtype": "Link",
   "in_list_view": 1,
   "label": "Freight RFQ",
   "options": "Freight RFQ",
   "reqd": 1
  },
  {
   "fieldname": "incoterm",
   "fieldtype": "Link",
   "label": "Incoterm",
   "options": "Incoterm"
  },
  {
   "fieldname": "package_mode",
   "fieldtype": "Select",
   "label": "Package Mode",
   "options": "\nFCL\nLCL"
  },
  {
   "fieldname": "transportation_by",
   "fieldtype": "Select",
   "label": "Transportation By",
   "options": "\nAir\nOcean"
  },
  {
   "fieldname": "mbl_number",
   "fieldtype": "Data",
   "label": "MBL Number"
  },
  {
   "fieldname": "hbl_number",
   "fieldtype": "Data",
   "label": "HBL Number"
  },
  {
   "fieldname": "voyage_number",
   "fieldtype": "Data",
   "label": "Voyage Number"
  },
  {
   "allow_bulk_edit": 1,
   "allow_in_quick_entry": 1,
   "fieldname": "containers",
   "fieldtype": "Table",
   "label": "Containers",
   "options": "Containers"
  },
  {
   "fieldname": "total_number_of_packages",
   "fieldtype": "Data",
   "label": "Total Number Of Packages"
  },
  {
   "fieldname": "shipping_order",
   "fieldtype": "Data",
   "label": "Shipping Order"
  },
  {
   "fieldname": "liner_name",
   "fieldtype": "Data",
   "label": "Liner Name"
  },
  {
   "fieldname": "column_break_lmfl",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "documents_tab",
   "fieldtype": "Tab Break",
   "label": "Documents"
  },
  {
   "fieldname": "workflow_state",
   "fieldtype": "Link",
   "hidden": 1,
   "label": "workflow_state",
   "options": "Workflow State"
  },
  {
   "fieldname": "service_type",
   "fieldtype": "Select",
   "label": "Service Type",
   "options": "\nImport\nExport"
  },
  {
   "fieldname": "po_pricing_tab",
   "fieldtype": "Tab Break",
   "label": "Pricing"
  },
  {
   "default": "0",
   "fieldname": "total_po",
   "fieldtype": "Currency",
   "label": "Total PO",
   "read_only": 1
  },
  {
   "default": "0",
   "fieldname": "total_so",
   "fieldtype": "Currency",
   "label": "Total SO",
   "read_only": 1
  },
  {
   "fieldname": "po_item",
   "fieldtype": "Table",
   "label": "PO Item",
   "options": "CHILD PO"
  },
  {
   "fieldname": "so_item",
   "fieldtype": "Table",
   "label": "SO Item",
   "options": "CHILD SO"
  },
  {
   "collapsible": 1,
   "fieldname": "scope_of_work_section",
   "fieldtype": "Section Break",
   "label": "Scope Of Work"
  },
  {
   "fieldname": "column_break_aevp",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "column_break_wihm",
   "fieldtype": "Column Break"
  },
  {
   "default": "0",
   "fieldname": "local_flow",
   "fieldtype": "Check",
   "label": "Local (Door-to-CY)"
  },
  {
   "default": "0",
   "fieldname": "freight_flow",
   "fieldtype": "Check",
   "label": "Freight (CY-to-CY)"
  },
  {
   "default": "0",
   "fieldname": "destination_flow",
   "fieldtype": "Check",
   "label": "Destination (CY-to-Door)"
  },
  {
   "fieldname": "cfs_supplier",
   "fieldtype": "Link",
   "label": "CFS Supplier",
   "options": "Supplier"
  },
  {
   "fieldname": "section_break_ywjf",
   "fieldtype": "Section Break"
  },
  {
   "depends_on": "eval: doc.package_mode == 'FCL'",
   "fieldname": "fcl_package",
   "fieldtype": "Table",
   "label": "FCL Package",
   "options": "FCL Package"
  },
  {
   "fieldname": "section_break_ywtr",
   "fieldtype": "Section Break"
  },
  {
   "depends_on": "eval: doc.package_mode == 'LCL'",
   "fieldname": "lcl_package",
   "fieldtype": "Table",
   "label": "LCL Package",
   "options": "LCL Package"
  },
  {
   "fetch_from": "freight_rfq.customer",
   "fieldname": "customer",
   "fieldtype": "Link",
   "label": "Customer",
   "options": "Customer",
   "read_only": 1,
   "reqd": 1
  },
  {
   "fieldname": "vessel_name",
   "fieldtype": "Data",
   "label": "Vessel Name"
  },
  {
   "fieldname": "section_break_dqvc",
   "fieldtype": "Section Break"
  },
  {
   "allow_bulk_edit": 1,
   "fieldname": "document_list",
   "fieldtype": "Table",
   "label": "Document List",
   "options": "Upload Documents"
  },
  {
   "fieldname": "gross_weight",
   "fieldtype": "Float",
   "label": "Gross Weight"
  },
  {
   "fieldname": "volume",
   "fieldtype": "Float",
   "label": "Volume (CBM)"
  },
  {
   "fieldname": "freight_charge_type",
   "fieldtype": "Select",
   "label": "Freight Charge Type",
   "options": "Credit"
  },
  {
   "fieldname": "invoice_number",
   "fieldtype": "Data",
   "label": "Invoice Number"
  },
  {
   "fieldname": "master_bl_shipper",
   "fieldtype": "Data",
   "label": "Master BL Shipper"
  },
  {
   "fieldname": "master_bl_consignee",
   "fieldtype": "Data",
   "label": "Master BL Consignee"
  },
  {
   "fieldname": "master_bl_notifyparty",
   "fieldtype": "Data",
   "label": "Master BL Notifyparty"
  },
  {
   "fieldname": "house_bl_shipper",
   "fieldtype": "Data",
   "label": "House BL Shipper"
  },
  {
   "fieldname": "house_bl_consignee",
   "fieldtype": "Data",
   "label": "House BL Consignee"
  },
  {
   "fieldname": "house_bl_notifyparty",
   "fieldtype": "Data",
   "label": "House BL Notifyparty"
  },
  {
   "fieldname": "workflow_history",
   "fieldtype": "Table",
   "label": "Workflow History",
   "options": "Workflow History"
  },
  {
   "fieldname": "workflow_tab",
   "fieldtype": "Tab Break",
   "label": "Workflow"
  },
  {
   "collapsible": 1,
   "fieldname": "section_break_ftkc",
   "fieldtype": "Section Break",
   "label": "Containers"
  },
  {
   "fieldname": "eta",
   "fieldtype": "Date",
   "label": "ETA"
  },
  {
   "fieldname": "ata",
   "fieldtype": "Date",
   "label": "ATA"
  },
  {
   "fieldname": "invoice_value",
   "fieldtype": "Float",
   "label": "Invoice Value"
  },
  {
   "fieldname": "net_weight",
   "fieldtype": "Float",
   "label": "Net Weight"
  },
  {
   "collapsible": 1,
   "fieldname": "master_bl_details_section",
   "fieldtype": "Section Break",
   "label": "Master BL Details"
  },
  {
   "fieldname": "column_break_bate",
   "fieldtype": "Column Break"
  },
  {
   "collapsible": 1,
   "fieldname": "house_bl_details_section",
   "fieldtype": "Section Break",
   "label": "House BL Details"
  },
  {
   "fieldname": "column_break_xmip",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "cfs_code",
   "fieldtype": "Data",
   "label": "CFS code"
  },
  {
   "fieldname": "tab_5_tab",
   "fieldtype": "Tab Break",
   "label": "DO"
  },
  {
   "fieldname": "boe_tab",
   "fieldtype": "Tab Break",
   "label": "BOE"
  },
  {
   "fieldname": "boe_date",
   "fieldtype": "Date",
   "label": "BOE date"
  },
  {
   "fieldname": "column_break_troy",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "boe_type",
   "fieldtype": "Select",
   "label": "BOE Type"
  },
  {
   "fieldname": "boe_status",
   "fieldtype": "Select",
   "label": "BOE Status"
  },
  {
   "fieldname": "empty_return_date",
   "fieldtype": "Date",
   "label": "Empty Return Date"
  },
  {
   "fieldname": "vessel_unloading_date",
   "fieldtype": "Date",
   "label": "Vessel Unloading Date"
  },
  {
   "fieldname": "do_obtained_date",
   "fieldtype": "Date",
   "label": "DO Obtained Date"
  },
  {
   "fieldname": "column_break_qerr",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "do_valid_till",
   "fieldtype": "Date",
   "label": "DO Valid Till"
  },
  {
   "fieldname": "examination_date",
   "fieldtype": "Date",
   "label": "Examination Date"
  },
  {
   "fieldname": "assessment_date",
   "fieldtype": "Date",
   "label": "Assessment Date"
  },
  {
   "fieldname": "assessable_value",
   "fieldtype": "Float",
   "label": "Assessable Value"
  },
  {
   "fieldname": "duty_value",
   "fieldtype": "Float",
   "label": "Duty Value"
  },
  {
   "fieldname": "ooc_number",
   "fieldtype": "Data",
   "label": "OOC Number"
  },
  {
   "fieldname": "ooc_date",
   "fieldtype": "Date",
   "label": "OOC Date"
  },
  {
   "fieldname": "transport_tab",
   "fieldtype": "Tab Break",
   "label": "Transport"
  },
  {
   "collapsible": 1,
   "fieldname": "description_section",
   "fieldtype": "Section Break",
   "label": "Description"
  },
  {
   "fieldname": "description",
   "fieldtype": "Text Editor",
   "label": "Description"
  },
  {
   "fieldname": "transport_containers",
   "fieldtype": "Table",
   "label": "Transport Containers",
   "options": "Transport Containers"
  },
  {
   "fieldname": "do_status",
   "fieldtype": "Select",
   "label": "DO Status"
  },
  {
   "fieldname": "number_of_queries",
   "fieldtype": "Int",
   "label": "Number of Queries"
  },
  {
   "fieldname": "do_free_days",
   "fieldtype": "Data",
   "label": "DO Free Days"
  },
  {
   "fieldname": "good_description_section",
   "fieldtype": "Section Break",
   "label": "Good Description"
  },
  {
   "allow_bulk_edit": 1,
   "fieldname": "freight_items",
   "fieldtype": "Table",
   "label": "Freight Items",
   "options": "Freight Items"
  },
  {
   "collapsible": 1,
   "fieldname": "igm_details_section",
   "fieldtype": "Section Break",
   "label": "IGM Details"
  },
  {
   "fieldname": "igm_filing_date",
   "fieldtype": "Date",
   "label": "IGM Filing Date"
  },
  {
   "fieldname": "igm_inward_date",
   "fieldtype": "Date",
   "label": "IGM Inward Date"
  },
  {
   "fieldname": "other_tab",
   "fieldtype": "Tab Break",
   "label": "Other"
  },
  {
   "fieldname": "telex_release",
   "fieldtype": "Select",
   "label": "Telex Release",
   "options": "\nYes\nNo"
  },
  {
   "default": "0",
   "fieldname": "ssr_status",
   "fieldtype": "Check",
   "label": "SSR status"
  },
  {
   "fieldname": "do_extended_days",
   "fieldtype": "Int",
   "label": "Number of Extended Days"
  },
  {
   "fieldname": "cfs__hbl_manifest_tab",
   "fieldtype": "Tab Break",
   "label": "CFS / HBL Manifest"
  },
  {
   "fieldname": "hbl_manifestation_status",
   "fieldtype": "Select",
   "label": "HBL Manifestation Status"
  },
  {
   "fieldname": "column_break_fdzf",
   "fieldtype": "Column Break"
  },
  {
   "fieldname": "cfs_nomination_status",
   "fieldtype": "Select",
   "label": "CFS Nomination Status"
  },
  {
   "fieldname": "boe_number",
   "fieldtype": "Data",
   "label": "BOE Number"
  },
  {
   "fieldname": "examination_mark",
   "fieldtype": "Select",
   "label": "Examination Mark"
  },
  {
   "fieldname": "form_13_release_date",
   "fieldtype": "Date",
   "label": "Form 13 Release Date"
  },
  {
   "fieldname": "port_movement_date",
   "fieldtype": "Date",
   "label": "Port Movement Date"
  },
  {
   "fieldname": "section_break_urln",
   "fieldtype": "Section Break"
  },
  {
   "fieldname": "sa_service_type",
   "fieldtype": "Link",
   "label": "SA Service Type",
   "options": "SA Freight Service Type"
  }
 ],
 "index_web_pages_for_search": 1,
 "links": [],
 "modified": "2024-01-23 13:18:17.646901",
 "modified_by": "Administrator",
 "module": "Stockarea",
 "name": "Freight JOB",
 "naming_rule": "Autoincrement",
 "owner": "Administrator",
 "permissions": [
  {
   "create": 1,
   "delete": 1,
   "email": 1,
   "export": 1,
   "print": 1,
   "read": 1,
   "report": 1,
   "role": "System Manager",
   "share": 1,
   "write": 1
  }
 ],
 "sort_field": "modified",
 "sort_order": "DESC",
 "states": [],
 "track_changes": 1
}

i just want to know the fields available in you DocType along with child table fields

JSON do not contains the fields within child table

As you can see above, there is a field which is a table and linked to a child table called Upload Documents

Now I want multiple fields inside this doctype to get linked to the same table. But when doing so, how will I fetch them back from the database and assign which entry should go to which docfield?

Doctype - Freight Job
Field Name - Documents
Field Type - Table

Child Table Name = Upload Documents
fields here are

  1. document (attach type)
  2. Document Name (data type)
  3. Type (to give it a category) { this category I made to divide the documents and maybe show to different fields }

Please use this code on your first child table in frappe js as reference
// Function to sync child tables

First_Table: function(frm) {

    var first_table = frm.doc.First_Table || [];

    frm.doc.Second_table = [];

    $.each(first_table, function(i, row) {
        var newRow = frappe.model.add_child(frm.doc, 'Second_table');
        newRow.field1 = row.field1;  // Replace with actual field names
        newRow.field2 = row.field2;  // Replace with actual field names
        // Add more fields as needed
    });

    // Refresh the Second_table field to reflect the changes
    frm.refresh_field('Second_table');
}

I don’t think you got my questions @hemant.tripathi

I don’t want to sync child tables.

I want each docfield to have different data, but both should link to same child table.

So do you want to use same child table twice in one parent where the child table option is same?