Validate Dates on Change Request

DevYadav
Tera Contributor

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!!

 

 

 

 

3 REPLIES 3

Vismit Ambre
Giga Guru

Hi Dev,

 

Are you getting any values in cd, ed, sd ?

Hi @Vismit Ambre ,

these variables stores the value of current start date and end dates etc.

And for testing purposes.

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