Fetch Field from Child Table

Good Day All

I created a Custom Doctype with a Custom Child Table. Each row of the child table has a field for amount, Docfield type is Currency, and the goal is to fetch the most approximate amount of the main amount in the parent Doctype, from the child table and place next to the main amount in the parent Doctype.

This is the code I wrote, but it’s not working properly:

validate: function (frm) {
const rtcPrice = frm.doc.rtc_price;    
var child_table = frm.doc.competitor_table;
    console.log("child_table",child_table)
     const output = child_table.reduce((prev, curr) => Math.abs(curr - rtcPrice) < Math.abs(prev - rtcPrice) ? curr : prev);
     frm.set_value( "value__price", output.amount);
}

(competitor_table) is the child table
(rtc_price) is the standard amount
(value__price) is the target field
(output.amount) is the amount field in child table

Can you please help me with this code ?
Thank you :slight_smile: