Date Validation

Hi,all i am trying to set due date based on delivery date and tern(i.e a static select Options like 3 days ,7 days …)
requirement is when i select “3 days” option the due date will be delivery date + 3 days.
when i select “7 days” option the due date will be delivery date + 7 days.
i am trying with this script… kindly give your suggestions it will help me to solve it.

frappe.ui.form.on(‘Sales Order’,‘onload’, function(frm){

cur_frm.cscript.custom_delivery_date = function(doc) {
if (doc.delivery_date == frappe.datetime.get_today() && doc.term == "3 Days") {
    frm.set_value("due_date", frappe.datetime.add_days(doc.delivery_date, 3));		


frappe.ui.form.on(‘Sales Order’, {
        if (frm.doc.delivery_date == frappe.datetime.get_today() && frm.doc.term == "3 Days") {
             frm.set_value("due_date", frappe.datetime.add_days(frm.doc.delivery_date, 3));		

@szufisher thanks for your response .
i want to update due date while selecting different term options…
i.e for 3 days-delivery date+ 3,
for 7 days-delivery date+ 7,
for 15 days-delivery date+ 15

Hi @shivansh13,
If you explain the problem or error you get, it might be clearer for someone here to help you.
And it is not clear whether you want the change to happen right away when you make the change or when the delivery date due (same date as today).

Aside of that, why are you not writting something like this:

if (doc.term == "3 Days") {
  days = 3;
} else if (doc.term == "7 Days") {
  days = 7;
} else if (doc.term == "15 Days") {
  days = 15;

if (doc.delivery_date == frappe.datetime.get_today()) {
   frm.set_value("due_date", frappe.datetime.add_days(frm.doc.delivery_date, days));
1 Like

@rahy thanks for your response…let me check with it and i will revert back soon

@rahy i tried with it but its not working. while selecting static option due date should change too… thanks for your response…

So I assume you want the change happen directly when you make change to the term. If so, use the same code but remove the if condition.

@rahy exactly that is required…let me try and i will revert back…thanks for your response