How Can I Bind One Field With Other Fields In Child Table

I have a table having a child’s table

Child table has 4 fields , ‘Field-1’, ‘Field-2’, ‘Field-3’, ‘Field-4’

I want ‘Field-4’ to be like ‘Field-1’ + ‘Field-2’ + ‘Field-3’ and whenever any change is happening on any first 3 fields, field 4 can get updated.

I want this to do through Form Scripts. My Fiield-4 field is a currency field

Hi @Abhiraj_Tulsyan:

Use client script, something like this:

frappe.ui.form.on('yourdoctype', {
	refresh(frm) {
		// your code here
	}
})

frappe.ui.form.on('yourchilddoctype', {

    field1(frm, cdt, cdn) {
        getField4(frm, cdt, cdn)
    },
    field2(frm, cdt, cdn) {
        getField4(frm, cdt, cdn)
    },
    field3(frm, cdt, cdn) {
        getField4(frm, cdt, cdn)
    },
    
})

function getField4(frm, cdt, cdn){
    var row = locals[cdt][cdn];
    var total = row.field1 + row.field2 + row.field3
    frappe.model.set_value(cdt, cdn, "field4", total)
}

Check docs for more info:
https://frappeframework.com/docs/user/en/api/form

And take a look to this amazing stuff:

Hope this helps.

Hello @avc
What is that locals variable in row = locals[cdt][cdn]?
I can’t find anything like that in the API Docs

Hi @Abhiraj_Tulsyan:

locals is a namespace provided by the framework, containing the doc and metadata loaded in your browser.

Is broadly used.

@avc
Is there a doc available related to it so I can study it and its associations?

Hi @Abhiraj_Tulsyan:

I think there is not document about it, but try to exploring locals in java console and how is used on Frappe or ERPNext code.

Hope this helps.