Get day of the date in child row from document field

Hi, can anyone help me with this?

How can I fetch the day in the “From” date, and put it in the table if particulars is “Date” for the column “Sunday”? Can someone help me correct my script?

Doctype = Sales Expense Liquidation
Table = Sales Liquidation Header

frappe.ui.form.on('Sales Expense Liquidation', {
	refresh(frm) {
	   frappe.ui.form.on("Sales Liquidation Header", {
		    period_from: function (frm) {
		        var child_row = locals[cdt][cdn];
		        if (child_row.sales_liquidation.particulars == "Date")
                    frappe.model.set_value(child_row.doctype, child_row.name, "sunday", moment(frm.doc.period_from).format('dd'));            
		    }
	    });
	}    
});

Hi. Try this.

frappe.ui.form.on('Sales Expense Liquidation', {
    refresh: function(frm) {
        if (frm.doc.date) {
            var date = new Date(frm.doc.date);
            var dayOfMonth = date.getDate();

            $.each(frm.doc.sales_liquidation_header || [], function(i, d) {
                if (d.particulars === 'Date') {
                    frappe.model.set_value(d.doctype, d.name, 'sunday', dayOfMonth);
                }
            });
        }
    }
});


You will have to modify the name of your fields, etc.

It’s a good base to start

1 Like

Unfortunately it’s not working :smiling_face_with_tear:

frappe.ui.form.on('Sales Expense Liquidation', {
    refresh: function (frm) {
    },
    from: function (frm) {
        var fromValue = frm.doc.from;


        if (fromValue) {

            var day = new Date(fromValue).getDate();

        } else {

            var day = null;
        }


        var childTable = frm.doc.header;
        $.each(childTable, function (index, row) {
            if (row.particulars === "Date") {
                frappe.model.set_value(row.doctype, row.name, 'sunday', day);
            }
        });

        frm.refresh_field('header');
    }
});

New code. Tested and Working:

You will have to modify the name of your fields, etc.

Thank you so much! Works perfectly