Trying to get a business rule to compare date/time field to current date/time and set a variable

jjones4773
Tera Guru

I have the following script:

 

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('x_uno15_nrapp_push_notification');
gr .addEncodedQuery('scheduled_onISNOTEMPTY');
gr .query();

var scheduled = new GlideDateTime(getValue('scheduled_on'));
var nowdatetime = new GlideDateTime();

while (gr .next()) {
    if (scheduled >= nowdatetime)
   
{
    gr .setValue('state', send-ready);
    gr .update();
}
}

})(current, previous);
 
jjones4773_0-1709045383171.png

 

I want to change the state to 'send-ready' when the current date/time matches or surpasses the 'scheduled_on' date/time.

 

Thanks for any assistance.

 

Jason

1 REPLY 1

AJ-TechTrek
Giga Sage
Giga Sage

Hi @jjones4773 ,

 

There are couple of solve community articles available, refer these.

 

https://www.servicenow.com/community/itsm-forum/compare-current-date-with-pre-defiend-date-on-a-busi...

 

https://www.servicenow.com/community/developer-forum/how-to-compare-two-dates-i-e-glidedatetimes-wit...

 

https://www.servicenow.com/community/itom-forum/compare-date-time-on-2-variables/m-p/901603

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.

 

Thanks

AJ

Linkedin Profile:- https://www.linkedin.com/in/ajay-kumar-66a91385/

ServiceNow Community Rising Star 2024