- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 01:37 AM
Hi All,
I am trying to restrict the past Date using the BR but i am not able to do it and getting the error .Can any one help me on this . Let me know if any modifications has to be done in the Code
Script :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:15 AM
Hi @sushma9
First thing ((current.u_arrival_date), there is extra braces '(' you used.
second thing compareTo is generally used in string type and date not in string it is object
you can use code like below, if comparision on today
var dateField = new GlideDateTime(current.u_arrival_date);;
var nowTime = new GlideDateTime(); // current date and time
var dur = new GlideDuration();
dur = GlideDateTime.subtract(dateField, nowTime);
var days = dur.getDayPart();
gs.info(days);
if(days>0){
gs.info("Arrival date can not be in past");
}
Please check and Mark Helpful or correct if it really helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:29 AM
its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 03:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 04:31 AM
Its working now and i have added some other code and executed its working fine but return confirm(); is not working for me.
Script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 06:58 PM
With the above code i am able to validate the dates but the records are getting created .How to stop the records if the invalid selection is taken.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:44 AM
why to use business rule for this?
why not handle this using onchange or onSubmit script
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader