Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Send email notification when date is reached

riaz_mansuri
Kilo Guru

Hi,

I want an email to be sent when a specific date field has reached 30 days before the actual date.

I have set this on the contracts table but is it not working, does anyone know a script I can use?

find_real_file.png

The field is a date field called u_review_date

When this is less than 30 days away and email notification should be triggered.

Any ideas?

Thanks

1 ACCEPTED SOLUTION
23 REPLIES 23

The scheduled job would look something like this.


Standard disclaimer: The following code is untested, requires review and potential modifications.



(function () {


      // Get a list of records that are coming due


      var rec = new GlideRecord('u_contract'); // Use the right table, I made this one up


      rec.addQuery('u_review_date', '<=', gs.daysAgo(-30)); // Get records updated -30 days ago (in the future)


      rec.addNullQuery('u_reminder_date'); // and not already reminded


      rec.query();



      while (rec.next()) {


                  gs.eventQueue('contract.reminder', rec, '', '');


                  rec.u_reminder_date = new GlideDateTime();


                  rec.update();


      }


})();


better formatting, more eloquent, and a disclaimer to boot!


riaz_mansuri
Kilo Guru

Thank you - I will try the above tomorrow ad update this thread



Riaz


riaz_mansuri
Kilo Guru

Hi,



I have decided to do this via a workflow as I want a ticket created as well and an Incident.



In the Begin I have a Filter condition of State is Active



What should the next box contain, a Timer or a Wait for condition?



I only want the workflow to Trigger if the Date Field Review Date is 30 days away.



I cant seem to find how to start this trigger.



Thanks,


Riaz


A timer activity should do very well here Riaz.



Timer Activities - ServiceNow Wiki