Dynamically add fields using server side script

I’m new to erpnext and I’m stuck in a complex way of generating a form. I have a list of equipments (machinery) which will have basic metadata and a list of parameters which are inputs.

  1. User would create a new equipment
  2. Fill in meta data like purchase date, manufacturer, serial number/reference number, project it belongs to
  3. A section where the machinery’s parameters are added → Field Name, units and input/output. It can have many inputs and outputs. For example, in case of a water boiler, the fields would be Water, coal/electricity as input and steam as output.

The parameters are a separate child table doctype and is linked to primary. I can now add a new equipment and get the params set in all one place.

Now, I will need to have a separate doc type which lets the user selects the project which should dynamically fetch all the equipment linked to the project and create sections for each equipment with all the equipment parameters to be collected from the user.

With the above boiler example, let’s say project 1 has 3 boilers. Once I select project 1, how could I get the server side script to fetch all equipments and their equipment fields then loop through the equipments to create sections dynamically along with their params?