Help needed to Write a small custom script

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 er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@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.

 

 

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 <ad...@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 er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@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.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

 

 

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 <ad...@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 er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@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.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

 

 

Hi Anand,

Thanks, works flawlessly.


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 <ad…@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+un…@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.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/4BWGHB-LGxUJ.

For more options, visit https://groups.google.com/groups/opt_out.

 

 

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 <ad…@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+un…@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.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/6yidCxZcMEcJ.

For more options, visit https://groups.google.com/groups/opt_out.

 

 

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.

On 13-Aug-2012, at 1:02 PM, Aditya Duggal <ad...@gmail.com> wrote:

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 <ad...@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+un…@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.

 

 





You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/6yidCxZcMEcJ.

For more options, visit https://groups.google.com/groups/opt_out.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

 

 

Thanks alot,

This code works flawlessly

On Monday, August 13, 2012 1:21:36 PM UTC+5:30, Anand Doshi wrote:

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.

On 13-Aug-2012, at 1:02 PM, Aditya Duggal <ad…@gmail.com> wrote:

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 <ad…@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 er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@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.

 

 





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+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/6yidCxZcMEcJ.

For more options, visit https://groups.google.com/groups/opt_out.

 

 




You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/eGLlhlk-Bx4J.

For more options, visit https://groups.google.com/groups/opt_out.