When Date is Reached Automatically Send Email Notification to Requestor

eric987dc
Kilo Contributor

We currently have a solution which uses the Service Catalog - Items. After a requestor requests this item and it goes through the entire approval process. At the end, it will have a start date. Whatever that start date may be, we are trying to somehow record that date and set a timer so that 2.5 years from that start date, an email will be sent to that same requestor asking for their review. This same process on will repeat again 5.5 years and 8.5 years if the end date is long enough. We will need to condition this process to repeat only the number of times required by the length of the request. 

We did not want to put a wait for condition in the workflow because we wanted that request to be closed/complete.

We also need the ability to ask a few questions and obtain metrics on the number of reviews sent/replied/and their answers. 

What/How is the best method of completing this? 

Thanks for any help!

15 REPLIES 15

Aman Gurram
Giga Expert

How about scheduling an event?

 

You can use gs.eventQueueScheduled() to trigger an event at a specific time. It looks like this:

var futureDate = new GlideDateTime(); //TO-DO write some custom logic to set it to future

gs.eventQueueScheduled("event_name", current, "", "", futureDate);

 And trigger the Notification based off the above generated Event. You can execute custom server side scripts in the script actions for event to support your process. 

By triggering a scheduled event in your workflow run script activity your workflow will still continue to execute, that way the request will move towards completion. 

 

 

 

Giles Lewis
Giga Guru

You should create a custom table to manage this process. Your Service Catalog workflow can run a script to create a record in the custom table. The custom table will contain a link back to the original Service Catalog item. The custom table will also have a trigger date (or perhaps several) for events that need to happen in the future. You might need multiple custom tables: one for the reviews and another for the individual metrics.

You absolutely do not want to kick off a workflow that will run for such a long time. One issue is that your process is likely to evolve. When the process evolves you want the old requests to follow the new process, and not the original process. Instead of a workflow timer you should use a scheduled job once/week or once/day to scan the custom table to determine that it is time for a review, or whatever. The scheduled job creates a custom ServiceNow event (gs.eventQueue) which you have defined in the Event Registry table. The custom event then triggers the email notifications.

Instead of this new table you could do the same with a scheduled event as previous suggested. That event itself could trigger a workflow/mail/something else at the correct time. By doing that you don't need to have the workflow running until the event occurs, it's first by then the workflow will start.

Build a custom table is also possible, but if not needed I try to not create more tables than necessary. I do like the table suggestion though since it would be much clearer about which reviews has been send and when they are expected to be send instead of looking for a scheduled event.

eric987dc
Kilo Contributor

gflewis,

I have a custom table that has a script that pushed a start date to that table. However when creating a workflow condition to run 2 years after that start date was not a selectable choice. It seems the pre-set conditions would be tied to a maximum of 1 year. Is there a way around this?

I agree with comments above that you definitely don't want to launch a workflow that will sit for 2.5 years.  That would be very bad for many reasons.

If you have a table that stores the dates, my recommendation would be to create a scheduled job that runs once a day and queries this table for "expired" records - you determine what expired means like 30 days in advance of a date or the day of or whatever.  Then if it finds a record, it will launch a workflow, send an email, or do whatever you need to do.