scheduling jobs for weekly/bi-weekly/monthly

Likithsai
Tera Contributor

hi Capture 369.PNG

Hi Alan lowrance

This is Gopi ,Alan lowrance   i have a requirement , i have a project table and in that i have a "project reminder" section where in

Users can subscribe for Weekly/Bi-Weekly/Monthly reminders using the "Project Reminder" Section.

User should be able to select days (multi-select) on which reminder needs to be sent.can please help me to sort this issue.

What i have done :

.

Reminder tracker snapshot.PNG

For Weekday choice we have given   number(mon=1.tuesday=2..so on), we have multiple users who trys to enroll for "project reminder",what i have done is ,i have created a staging table and created same fields and written   a business rule   to pass the   values to staging table ,and i am able to pass the values,from here i am not able to move further,and i am new to servicenow tool ,can you   help me sorting out this issue .

8 REPLIES 8

Kaka Nayeem
Tera Guru

Is it user created table?


hi kaka Nayeem



yes it is user created table....


alan_lowrance
Mega Guru

Gopi, thanks for posting in a new thread!   The architecture I envisioned for this would consist of the following pieces:


Project Table w/ fields containing the technician's notification preferences.


Staging Table (not necessarily needed, but since you have it we'll use it). Populated by Business Rules that copy the notification-related fields from Project Table.   Note: Each staging table record needs a way of deactivating or being deleted when the project is complete.   Also needs a DateTime field to hold the last time a notification was sent (this DateTime needs to be cleared whenever the u_reminder_weekday or interval changes)


Event in the event registry that acts against the project table. Event will be triggered by a Scheduled Job.


Email Notification (can use a template or not), on project table so you can easily get access to all that info, triggered by the aforementioned event, target recipient passed as an event parameter.


Scheduled Job where all the conditions and logic runs to fire the events (one for each person receiving an email).   Ex: gs.eventQueue("name of event", StagingRecordObject.[projectRef_Field], StagingRecordObject.[userRef_Field]); and another event triggered for additional_recipient.   Could implement one of the scheduled job conditions to check to see which instance you are currently in so these won't fire in sub-prod instances... once you have tested they work of course.   Note: Scheduled Jobs aren't captured in Update Sets so you'll have to just copy the XML or copy-paste the script across instances if you're doing this in Update Sets.



I'll post a sample Scheduled Job in a few hours that will show how to check if weekly, bi-weekly, or monthly from the last date notified on your staging table.


In the meantime, sabell2012 what do you think of the design?   Using best-practices?


Here's a sample of the scheduled job.   You would set it to check every day at whatever time you want the notifications to go out... for example, every day at 9:30am


Note: Your reminder day should probably not be a multiple list, because what does it mean if you want to be reminded every week on Monday and Thursday?   We can't keep track of that with just one "last reminded" field.   And you can also get rid of the next reminder field since we don't need it if we're just going to keep track of the last time it ran and the next day of the week we should check again.



var today = (new GlideDateTime()).getDayOfWeekUTC();


var elig = new GlideRecord("staging_table");


elig.query('reminder_weekday',CONTAINS,today); //CONTAINS can be removed if no longer searching a list


while (elig.next()){


  if ((elig.reminder_frequency == 'Weekly' && elig.last_reminder <= gs.daysAgo(6))||(elig.reminder_frequency == 'Bi-Weekly' && elig.last_reminder <= gs.daysAgo(13))||(elig.reminder_frequency == 'Monthly' && elig.last_reminder <= gs.daysAgo(27))){


  gs.eventQueue("notificationName", elig.project, elig.user);


  if (elig.additional_recipient != '')


  gs.eventQueue("notificationName", elig.project, elig.additional_recipient);


  }


}



This should work, but of course I can't test it without all your variables and tables and stuff.


The only problem I see if on months where there's a 5th Monday or whatever.   So maybe you can check for the month of February and set it to make sure it's more than 29 days ago for all the other months?