Copy data when press add_row button and validate

i want to get data from parent doctype in linked field called “P” to his child table linked field Called “C” only when i press add row button and check all the table before for if it’s empty or not only when i press add_row button , thanks in advance

solution worked for me.

  var d=locals[cdt,cdn];
  frappe.model.set_value(cdt,cdn,'target field',value yyou want to add)