Child table value fetch from one doctype to a child table of another doctype

Doctype1 - Motor
ChildTable1 - insurer_child
Doctype2 - Polciy
ChildTable2 - recipients
common field for both doctype is prospect_id
@rmehta @MartinHBramwell @trentmu @gsarunk Hi! I need to fetch values from insurer_child from Motor doctype and add it to the recipents table in Policy Doctype.

Thanks…

Hi @Deepu1117

Please try this or Fetch values from a child table to another child table

1 Like

apart for @DaizyModi suggestion you can try this too

From the server side it is rather easy. if you are looking for client side script, first select the motor corresponding to the prospect of Policy and the get the child table values of obtained motor document like below. Once obtained you can add to the recipients table

frappe.call({
                                        //you can also use frappe.client.get_value
                			"method": "frappe.client.get_list",
                			"args": {
                				"doctype": "Motor",
                				filters: {prospect_id:frm.doc.prospect_id},
                				fields: [ 'name',],
                 			},
                			"callback": function(response) {
                                             // response.message will be an array of motors. in this case we will get only 
                                             // record
                			    console.log(response.message[0]);
                                             frappe.call({
                			            "method": "frappe.client.get_list",
                			            "args": {
                				         "doctype": "insurer_child",
                				         "parent": response.message[0].name,  //name of parent
                				         fields: [ 'name','other_fields'],
                 			          },
                			          "callback": function(response) {
                			               console.log(response.message);
                                                       //iterate the response and add child in the frm
                                                       for .....{
                                                             frm.add_child('recipients', {
                                                               field1: value from iteration,
                                                       
                                                        }
                                                          

                			        }
                		});
                			}
                		});

The above is just the approach. please fix the syntax and tailor it to your context. Hope this will help you

1 Like

@DaizyModi Thanks for your reply! .Will try this

@gsarunk Thanks for your effort & reply .I’m looking for the solution in Client side, will try this.

the above solution is for the client side only.

1 Like