How to Create a Timer Job with SharePoint Designer 2013

In this post I’m going to show you how to create a no server side code timer job using a SharePoint Designer 2013 site workflow.

Scenario

We have a SharePoint Online (Office 365) site with a task list in it and we need to send daily alerts to users that have overdue tasks assigned to them.

sp_task_list

Problem

The obvious solution would be to create a timer job to do that… Unfortunately we are in an Office 365 environment so we do not have the possibility to implement a standard timer job using server side code.

office_365_red

Solution

We can simulate the behaviour of a timer job using a Sharepoint Designer 2013 site workflow.

Steps

1. Create a New Site Workflow in Sharepoint Designer 2013

Open SharePoint Designer 2013 and create a new site workflow

site_wotkflow

2. Get All Overdue Tasks that are not Completed

In the first stage (let’s call it “Getting Overdue Tasks”) build a dictionary to store the accept header for our rest request and get results in json:

accept: application/json;odata=verbose

tj_build_dictionary

tj_accept_header

Put the current date in a DateTime variable (let’s call it “today”).

tj_today

Then call the SharePoint REST Service to get the overdue tasks.
To do so insert the “Call HTTP Web Service” action in the workflow (in an App Step to avoid permission related problems).

tj_call_service

The action url must be constructed dynamically  using the “today” variable like this:

tj_request_endpoint

tj_today_iso_formatted

Set the action verb to GET, the request headers to the headers dictionary previously built and the response content to a dictionary to store the request result.

tj_rest_call_properties

Get and store the returned tasks in a separate dictionary to count them and loop through them later.

tj_store_tasks

3. Send Alerts to Overdue Tasks Assignees

Create a second stage (let’s call it “Sending Alerts”) to send alerts and then link the first stage to it.

Insert a loop and inside it extract the task id from the rest response and send an email to each overdue task assignees.

Use a loop index variable to address the current task and remember to initialize it to zero and increment it properly at the end of the loop.

tj_loop

tj_mail

To get the email address of the recipient (the task assignee) use the task id previously extracted from the rest response like this:

tj_recipient

4. Wait One Day and Start Over Again

Insert a pause action and configure it to wait one day.

Link the “Sending Alerts” stage to the “Getting Overdue Tasks” stage to start over again.

tJ_pause

Conclusion

Here is how the complete workflow will look at the end of the process:

tj_complete_workflow

Publish the site workflow and start it (you can access the “Site Workflows” page from the “Site Contents” page).

tj_start_wf

It will send the alerts daily as expected.

tj_receive_mail

References

Fabian Williams

Advertisements

11 thoughts on “How to Create a Timer Job with SharePoint Designer 2013

  1. JB August 24, 2016 / 6:28 am

    Does this have to be started manually?

    Like

    • Maria Grazia Merlo August 25, 2016 / 4:16 pm

      Hi JB.
      Yes, that is the only option available for a site workflow in Office 365.

      Like

  2. westerdaled September 5, 2016 / 8:32 pm

    Hi Fabian. I am using this this approach to add 4 months to the current day to compare with ‘reissueDate’ held against a document in a library. I notice the action to add for months to a variable, also sets the time to 23:00. I wonder if this might impact filter (ReissueDate eq ‘variable:dateReissue’) as this returning no data for a valid HTTP code. Also with other request s I have need to apend /ListItemAllFields .. Can you see this being necessary.

    Like

    • westerdaled September 7, 2016 / 11:11 am

      Fabian, In the end I fired up Postman and successfully ran my REST call. looks like I do need to ensure my dates are in the ISO format and that I am dealing with the time part consistently $filter=(ReissueDate eq ‘2017-01-05T00:00:00Z’).

      Like

  3. Brian Hofmeister April 18, 2017 / 3:26 pm

    Thank you Maria for this article. Is this still the best method for creating a timer in O365 sharepoint? Also, is it still manual? Meaning someone has to click this button every day?

    Like

    • Maria Grazia Merlo April 29, 2017 / 3:06 pm

      Yes, I think it is the easiest way to do it in Office 365 unless you want to use Azure or an On-Premise server to create a classic timer job that uses the Client Side Object Model (CSOM) to access SharePoint. It is manual in the sense that you have to start it the first time (not every day!). The site workflow should be implemented so that it waits auntil the next day (or whatever period of time you choose) before executing its logic again.

      Like

  4. Markoz August 9, 2017 / 2:39 pm

    Why can’t I build the workflow for Sharepoint 2013? Only i can do it with SharePoint 2013.. What do I need? Greetings

    Like

  5. Markoz August 9, 2017 / 2:41 pm

    Sorry, I want to say “Only i can do it with SharePoint 2010”.. Thank you

    Like

    • Maria Grazia Merlo August 9, 2017 / 6:49 pm

      I have created this site workflow using a “SharePoint 2013” workflow. Why are you’re saying you cannot do it? What kind of errors/problems are you facing? Are you working in an On-Premises farm or Online? If you’re working in an On-Premises 2013 environment, have you properly installed and configured Workflow Manager? If you haven’t you will only be able to create old SharePoint 2010 workflows.

      Thank you,
      Maria Grazia.

      Like

  6. S Clark (Easy Bins Dumpster Rentals October 22, 2017 / 3:29 pm

    I don’t see a loop that would cause the workflow to restart from the top after the Pause. So, what’s the magic that allows that to happen?

    Like

    • S Clark (Easy Bins Dumpster Rentals October 22, 2017 / 3:31 pm

      Nevermind, I see that the Transition to Stage allows for returning to the top. (Sorry, was thinking that it would only allow jumping to stages below, not above.) Thanks for posting!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s