Compare current date with pre defiend date on a Business Rule

TejasviR
Tera Contributor

Hello Everyone.

My requirement is, need to compare with the current date and time with predefined date and time (Filled by user), if the current date and time breached or crossed the predefined date and time need to set the value on a text field 'yes' if not then set value 'no'.

 

Thanks in advance

1 ACCEPTED SOLUTION

Shakeel Shaik
Giga Sage
Giga Sage

Hi @TejasviR ,

 

Create OnLoad Client Script on Custom Table.

sample script:

var currentDate = new Date(); //Current Date
var plannedDate = new Date(gr.getValue('u_end_date')); //Planned End Date

if (currentDate.getTime() > plannedDate.getTime()) {

g_form.setValue('NameOFtheField','Yes');

} else{
g_form.setValue('NameOFtheField','No');
}



please change as per your requirement.

 

 

Please check and Let us know

 

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use simple client script as well for this without GlideAjax

Can you share your script used?

Regards
Ankur

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

chsumit
Kilo Expert

Hi,

In BR i am not sure how will you check the prefield date has been breached. What will be the condition to check this.

You can write a scheduled job and check there which will RUN when ever you set. 

var Cdate = new GlideDateTime();

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.query();
while(gr.next()){
var Fdate = gr.u_created_date;
if(Cdate > Fdate){
gr.check = 'true';
gr.update();
}
}

// Update the values accordingly

Thanks,

Sumit

Shakeel Shaik
Giga Sage
Giga Sage

Hi @TejasviR ,

 

Create OnLoad Client Script on Custom Table.

sample script:

var currentDate = new Date(); //Current Date
var plannedDate = new Date(gr.getValue('u_end_date')); //Planned End Date

if (currentDate.getTime() > plannedDate.getTime()) {

g_form.setValue('NameOFtheField','Yes');

} else{
g_form.setValue('NameOFtheField','No');
}



please change as per your requirement.

 

 

Please check and Let us know

 

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

Thank you.