Custom Script For Due Date - Only Working Days

Dear All,

I’m trying to get due date based on Date File Requested.

This is supposed for only Monday, Tuesday, Wednesday, Thursday and Friday.

Saturday and Sunday is not included.

Sample Script.

cur_frm.cscript.filing_date = function(doc, cdt, cd){
cur_frm.set_value(“filing_due_date”, frappe.datetime.add_days(doc.fling_date, 10));
}

Hi @123elbmuh,

Please apply custom/client script.

frappe.ui.form.on('Your DocType Name', {
    filing_date: function(frm) {
        var fd = frm.doc.filing_date;
        const currentDate = new Date(fd);
        
        const numToAdd = 10; // add days
        
        for (let i = 1; i <= numToAdd; i++) {
          currentDate.setDate(currentDate.getDate() + 1);
          if (currentDate.getDay() === 6) {
            currentDate.setDate(currentDate.getDate() + 2);
          }
          else if (currentDate.getDay() === 0) {
            currentDate.setDate(currentDate.getDate() + 1);
          }
        }
        
        frm.set_value('filing_due_date', currentDate);
	}
});

Then reload and check it.

Thank You!

2 Likes