How to add two field values and store it in the other field in same child doctype

I wanted to add two field values of child doctype and save the resulted value in another field in the same child doctype

Can anybody please help me out how to do it ?

This may help You, @bnmahesh0017

I should code this in main doctype custom script right.

yes, the DocType which the child table linked.

This code is not working

can you explain your process briefly? @bnmahesh0017
I’m not good at coding, I have tried this method, and its working, :upside_down_face:

frappe.ui.form.on(“child”, {
a: function(frm,cdt,cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “cc”, (d.a + d.b));

This is the code I have given, in which “child” is the child doctype name
a is the child field name to get the function triggered
a is field1
b is field2
c is fieldtotal

and field type which I have given is float

I should add a’s and b’s value and store it in c

please help me out with this

*sorry fieldtotal is cc

Here is my code

let grand_total = 0;
frappe.ui.form.on("child doctype name", {
    quantity: function(frm,cdt,cdn) {
    var d = locals[cdt][cdn];
    frappe.model.set_value(cdt, cdn, 'amount', (d.quantity * d.price));
    grand_total = grand_total + (d.quantity * d.price);

You can try this!.

bro like I want to add value of column “a” and column “b” and store the values in column “c”
how to do this ?

Use below script

frappe.ui.form.on("Child Table Name", {
	field1 function(frm,cdt, cdn){
		destination_field(frm, cdt, cdn);
	field2: function(frm, cdt, cdn){
		destination_field(frm, cdt, cdn);
var destination_field = function(frm, cdt, cdn) {
	var child = locals[cdt][cdn];
	frappe.model.set_value(cdt, cdn, "destination_field", child.field1 + child.field2);

class LibraryMember(Document):
    #this method will run every time a document is saved
    def before_save(self):
        self.full_name = f'{self.first_name} {self.last_name or ""}'


If the above snippet doesn’t work for you , make sure server side scripts are enabled, and then restart bench

bench --site <your_site> set-config server_script_enabled true