Data Population into a Child Doc from a database table

Hello Guys,

I want to use a custom button to populate data into a child doc as follows:

  1. User will click a button.
  2. Script will get the records from a table in the same database.
  3. For each record one row will be added in the child doc and data will be populated.

This is similar to ERPNext’s “Get Items From” > “Material Requisition”.
What is the easiest way of doing. Appreciate code sharing, if anyone already have done it.