Planned start date must be after current date

Black Coder
Tera Guru

In the change request I have to validate the Planned start date that it should be after the current date. I was able to create the Field level error message whenever the planned start date is earlier than the current date. But regardless of that field-level error, when a user submits the form, the wrong value is getting updated.

How can we prevent the user from submitting a form if the planned start date is selected with earliar date

 

14 REPLIES 14

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you considered using a (Catalog) UI Policy to achieve date validations? There's almost no-code needed to achieve date validations this way. Have a look at an article I wrote on this:
No Code date validations thru (Catalog) UI Policies

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should be using before insert/update BR to stop the form submissions

Condition: Planned Start Date Changes AND Planned Start Date is not empty

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

var start = new GlideDateTime(current.start_date);

var nowTime = new GlideDateTime();

if(start.getNumericValue() < nowTime.getNumericValue()){

gs.addErrorMessage('Planned start date cannot be earlier than current time');
current.setAbortAction(true);

}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

to stop form submission you should be using onSubmit or before business rule

convert your client script to onSubmit and it should work fine

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

as you mentioned, I converted the client script to onSubmit. since it is not working ,I am not sure whether I made mistake on the script. if it is so can you please correct it