How to stop back date entry

Dear Experts,

1 - Is there a way to stop back date entry in the who system?
2 - Can we restrict back date entry in one or two options?

Thanks

Read the docs:

Custom Script Documentation ERPNext

Date Validation Link

If I want to restrict user based on sales order date, what changes should I make in following script.

frappe.ui.form.on(“Task”, “validate”, function(frm) {
if (frm.doc.from_date < get_today()) {
msgprint(__(“You can not select past date in From Date”));
validated = false;
}
});

@Zahid.Butt

I would rather use cscript for date field to alert user if he selects date past to current date and dont let him continue. :smile: :wink:

Can you please share the script to restrict back date entry in sales order.

Regards.

@Zahid.Butt
Date on Sales Order Form is by default Today. If you don’t want this, remove Default option from Customize form for Date(transaction_date).

for Validate transaction_date use below script - to avoid past date.

frappe.ui.form.on("Sales Order", "validate", function(frm) {
	if (frm.doc.transaction_date < get_today()) {
		msgprint(__("You can not select past date"));
		validated = false;
	}
});

Thanks it works.
One thing please, can I use "get_today()-3 " to validate 3 days back.

@Zahid.Butt
you can not use directly get_today()-3 because get_today() is in date format.
for that you can use add_days function for change date. Check this

frappe.ui.form.on("Sales Order", "validate", function(frm) {
    var date = frappe.datetime.add_days(get_today(), -3);
    if (frm.doc.transaction_date < date)  {
        msgprint(__("You can not select this date"));
        validated = false;
    }
});
3 Likes

Thanks a lot. Great job.

Best regards,

Zahid Butt

@Zahid.Butt

So this way as user enters value which is less than defined value user will get an alert and date will be cleared in the real time.

frappe.ui.form.on("Sales Order", "transaction_date", function(frm) { var p = frm.doc; var date = frappe.datetime.add_days(get_today(), -3); if (frm.doc.transaction_date < date) { frappe.model.set_value(p.doctype, p.name, "transaction_date", ""); alert("You can not select this date"); } });

Thanks Nick. Its done.

Regards,

Zahid

Hello Sangram

Same code how to write in Python
Can you guide me i want to add in Server Script Doctype
I want to allows only yesterday and present Date Submission

regards
Harshal