Friday, February 19, 2016

Steps to create SharePoint 2013 Designer Site Workflow

In this post I am going to create a simple SharePoint designer workflow which will act as a daily scheduler to send reminder email notifications. We will be using web service (REST) call from the workflow to get records from the SharePoint list.


1. Open SharePoint designer and click on Site Workflow button to create new workflow


2. Enter workflow name and ensure that in Platform Type SharePoint 2013 Workflow is selected and click OK.


3. Add new action "Add Time to date" to get 10 days previous date from today's date and configure it as shown in below screen shot. (I am setting it to get 10 days previous from today's you can configure it as per your requirement)



4. Now convert date object in string to pass that date in REST call, to do that add new string variable and add new action "Set Workflow Variable" to set newly added variable and then take sub string from that string variable by using action "Extract Substring from start of sting" as shown in below screen shot. 

5. Then create two dictionary variables to make REST call. To do that first add two new variable called ResponseContent and ResponseHeaders of type dictionary. and then set ResponseHeaders variable using action "Build Dictionary" and add two properties to dictionary as Accept and Content-Type with value application/json;odata=verbose to make REST Call.

6. Then we are ready to make REST call to fetch data from task list or any other data source. To call rest add action "Call HTTP Web Service" and configure it as below. 
  a) Set web service url: In my case I am using below rest url
<SiteUrl>/_api/lists/getByTitle('Workflow Tasks')/items?$select=DueDate,AssignedTo/Title,AssignedTo/EMail,AssignedTo/Name,AssignedTo/Id&$expand=AssignedTo&$filter=DueDate lt '[%Variable: stringDate%]'
  b) Set HTTP method to "HTTP GET"
  c) Set ResponseContent variable in ResponseContent section
  d) Set ResponseHeaders variable in ResponseHeaders  section
  e) add log activity and log responseCode to check call back status


7. Then we need to iterate trough content returned by the service, to do that add action called "get" and configure as below: 
  a) Add new variable called dataset to get items array from ResponseContent 
  b) Add action get
  c) Configure item path as d/results 


8. Then add action called count items to get count of returned items as below 


9.  Add one more integer variable called index and initialize it to Zero as shown below.


9.  Add loop n times activity to iterate through each task and configure it to iterate loop as per the tasks count as shown below.


10. Now its time to get task details in WF variables for further use as below: 
      a) Create one more variable called taskItem of type dictionary and get task object in  that variable.
      b) Get task title and assigned to email fields from the taskItem variable. as shown below



11. Add email activity and configure as shown below to send email notification. 


12. Now don't forget to increment index variable to work looping logic properly as shown below


13. Now most of the task is done, but remaining task is important and tricky to make Workflow work as scheduler or timer job. 
      a) Add new step called WF Sleep Mode
      b) Add newly added step to Transition to stage of previous step.
      c) Add new activity called Pause for duration configure it as per your requirement in my case I             am setting it to pause for one day.
      d) And finally set  Transition to stage to WF Initiation stage it will make WF go in endless                 loop and wait for one day on every iteration as shown below.




Thank you for spending time to read my blog. Please feel free to give suggestion, correction or add comments on my post.