Help needed to Write a small custom script

212 views
Skip to first unread message

Aditya Duggal

unread,
Aug 11, 2012, 10:39:13 AM8/11/12
to erpnext-dev...@googlegroups.com
I need help to write a small custom script which would check the Sales Order Date with the current date at the time of SAVING or SUBMITTING a SO and would not allow the user to save or submit it on a date which earlier than TODAY.

So SO_Date >= Today() is the condition I want to be checked at the time of saving or submitting a SO.

Anand Doshi

unread,
Aug 13, 2012, 1:30:56 AM8/13/12
to erpnext-dev...@googlegroups.com
Hi Aditya,

you can paste this in the Custom Script of Sales Order:

cur_frm.cscript.custom_validate = function(doc, dt, dn) {

// if there is existing content in custom_validate paste only this part within the curly braces of custom_validate
if (wn.datetime.str_to_obj(doc.transaction_date < new Date()) {
validated = false;
webnotes.msgprint("Sales Order Date cannot be a past date");
} );
// paste till here
}

This should do the trick.

Thanks,
Anand.

On 11-Aug-2012, at 8:09 PM, Aditya Duggal <aditya...@gmail.com> wrote:

I need help to write a small custom script which would check the Sales Order Date with the current date at the time of SAVING or SUBMITTING a SO and would not allow the user to save or submit it on a date which earlier than TODAY.

So SO_Date >= Today() is the condition I want to be checked at the time of saving or submitting a SO.

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/NCJtffLcaZYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Anand Doshi

unread,
Aug 13, 2012, 1:54:39 AM8/13/12
to erpnext-dev...@googlegroups.com
Hi Aditya,

There is a syntax error in the reply I sent.. please find the corrected script below:

cur_frm.cscript.custom_validate = function(doc, dt, dn) {

// if there is existing content in custom_validate paste only this part within the curly braces of custom_validate
if (wn.datetime.str_to_obj(doc.transaction_date) < new Date()) {
validated = false;
msgprint("Sales Order Date cannot be a past date"); // or any other message you want..
}
// paste till here
}

Thanks,
Anand.

On 11-Aug-2012, at 8:09 PM, Aditya Duggal <aditya...@gmail.com> wrote:

I need help to write a small custom script which would check the Sales Order Date with the current date at the time of SAVING or SUBMITTING a SO and would not allow the user to save or submit it on a date which earlier than TODAY.

So SO_Date >= Today() is the condition I want to be checked at the time of saving or submitting a SO.

Message has been deleted

Aditya Duggal

unread,
Aug 13, 2012, 3:32:02 AM8/13/12
to erpnext-dev...@googlegroups.com
Hi Anand,

This works fine but only one problem that the Validation fails when the date is equal to the system date as well and in the code I cannot see anything which should reject the validation on the basis of the sales order date being equal to the Today's Date.


On Monday, August 13, 2012 11:24:39 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

There is a syntax error in the reply I sent.. please find the corrected script below:

cur_frm.cscript.custom_validate = function(doc, dt, dn) {

// if there is existing content in custom_validate paste only this part within the curly braces of custom_validate
if (wn.datetime.str_to_obj(doc.transaction_date) < new Date()) {
validated = false;
msgprint("Sales Order Date cannot be a past date"); // or any other message you want..
}
// paste till here
}

Thanks,
Anand.
On 11-Aug-2012, at 8:09 PM, Aditya Duggal <aditya...@gmail.com> wrote:

I need help to write a small custom script which would check the Sales Order Date with the current date at the time of SAVING or SUBMITTING a SO and would not allow the user to save or submit it on a date which earlier than TODAY.

So SO_Date >= Today() is the condition I want to be checked at the time of saving or submitting a SO.

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To unsubscribe from this group, send email to erpnext-developer-forum+unsub...@googlegroups.com.

Anand Doshi

unread,
Aug 13, 2012, 3:51:36 AM8/13/12
to erpnext-dev...@googlegroups.com
Hi Aditya,

Here is the corrected code:

cur_frm.cscript.custom_validate = function(doc, dt, dn) {

// if there is existing content in custom_validate paste only this part within the curly braces of custom_validate
if (wn.datetime.get_day_diff(new Date(), wn.datetime.str_to_obj(doc.transaction_date)) > 0) {
validated = false;
msgprint("Sales Order Date cannot be a past date"); // or any other message you want..
}
// paste till here
}

thanks,
Anand.

To unsubscribe from this group, send email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/6yidCxZcMEcJ.

Aditya Duggal

unread,
Aug 13, 2012, 1:28:36 PM8/13/12
to erpnext-dev...@googlegroups.com
Thanks alot,

This code works flawlessly
Reply all
Reply to author
Forward
0 new messages