Validate Dates on Change Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 11:45 PM
Hi All,
There is a requirement that in CR
start date and end date should not be equal to their old added ones, i.e. if 9 feb 2016 is already present on list CR then we are not be able to add 9 feb in another record. Similar condition for end date.
There is one another condition that start date and end date should not be present within previously added date. Like if start date is 9feb and end date is 15 feb then newly dates should not be present within these dates
I am using the BR with after and insert and update check:
(function executeRule(current, previous /null when async/) {
var gr=new GlideRecord('change_request');
gr.query();
var cd= new GlideDateTime('current.start_date');
var ed = GlideDateTime('gr.end_date');
var sd = GlideDateTime('gr.start_date');
gs.addInfoMessage(ed);
gs.addInfoMessage(sd);
if(cd.getNumericValue() <= ed.getNumericValue() || cd.getNumericValue() >= sd.getNumericValue()){
gs.addInfoMessage('error!!!! this date is present between previously created CRs');
current.setAbortAction(true);
}
})(current, previous);
Thanks in Advance!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 11:48 PM
Hi Dev,
Are you getting any values in cd, ed, sd ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 11:59 PM
Hi @Vismit Ambre ,
these variables stores the value of current start date and end dates etc.
And for testing purposes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 01:05 AM
I understand that it is for testing purpose. However, if your actual code has this line -
var cd= new GlideDateTime('current.start_date'); - it would not work because you are passing additional quotation marks around current.start_date. It ideally should be like this -
var cd= new GlideDateTime(current.start_date); //without quotes