- 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:08 AM - edited 07-05-2023 02:45 AM
Hello @sushma9 , there are some issues like extra parentheses and the comparison operator.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:20 AM
Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 02:37 AM
Check these loops.
Business Rule avoiding date in the past
Business Rule Checking For Future Date
I hope this helps.
Priyanka.
- 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.