Fetch data from a DocType's child table to another's

Look at this post, the solution I’ve posted at the end is used for populating a child table. You need to slightly modify the code to populate the child table for Doctype2.