Scrip getting child data

Hi all,

I’m new to scripts in ERPNext and the topics I came across didn’t really answer my question.

We have created a custom doctype called Shipment. In that doctype we have a section “Cargo” which consists of a table. In this table, we have the ability to add our previous Purchase Orders that are to be included in a specific shipment. For example: Shipment-0001 includes Purchase Orders PO-0001, PO-0002

Each Purchase Order is made up of Items. We want to be able to fetch the items within a specific purchase order to showcase it on our Shipment doctype. Ideally we have the following happen

  1. Create a new shipment
  2. Add Purchase Orders (that make up that specific shipment)
  3. Automatically fetches all the items that make up the Purchase Orders (and more information about the items)

Thank you very much

create a script that gets triggered upon change in purchase order field and use frappe.client.get to fetch data of that purchase order and use $.each to fill data onto the target child table