Client Script for Day of the Week on Child Table

Hi! Need help on client script for day of the week for a child table:

Doctype: Monthly Work Plan
Table field name: activities
Table Name: MWP Table

Within MWP Table:
field name is “date” and upon selection of date, day of the week should automatically populate in field name “day”

Help pls!

@mehmehly you need to the the day like it’s Monday or Tuesday ?

Yes. For example, if I select October 24, 2023 for field name “date” belonging to child table “MWP Table”, field name “day” belonging to child table “MWP Table” should return “Tuesday”. How do I code that in client script? @bahaou

@mehmehly Try this

frappe.ui.form.on("MWP Table", {
  date: function (frm, cdt, cdn) {
    var child_row = locals[cdt][cdn];
    if (child_row.date) {
        var day_of_date = moment(child_row.date).format('dddd');
        frappe.model.set_value(child_row.doctype, child_row.name, "day", day_of_date);
    }
  }
});

@mehmehly Is it worked for you ?

Worked perfectly! Thanks so much!

1 Like