SPCurrentContext Activities in Visual Studio 2013 Toolbox For SharePoint 2013 Workflows

This article explains how to use the SPCurrentContext toolbox activities in SharePoint 2013 workflows.

Implementation Procedure

  1. Create a new "SharePoint 2013 - Empty Project" as below and provide the name you want.



  2. Click Ok. In the next window provide the site collection name you want to deploy the project to and choose Sandboxed Solution.



  3. Click Finish and wait for some time to create the project.
  4. Right-click on the project and Add new Item as Workflow and provide the name you want.



  5. Click the Add button and wait for some seconds. Visual Studio will communicate with SharePoint.



  6. In the next window provide the name of the workflow and choose the List Workflow option and click Next.



  7. In the next window select List or Library, History List and Task List as below.



  8. Click Next. Leave it as the default selection (A user manually starts the workflow option).



  9. Click Finish. Then you will see the designer screen as below.



  10. Drag and drop the WriteToHistory Activity to the sequence from the Toolbox as shown below.



  11. Select the WriteToHistory activity and press F4 to open the properties window. In the properties window provide the display name as Log WF Started and click on the button (…) and provide the message as “WF Started” in the Expression Editor window.



  12. Repeat Step 11 for another WriteToHistory activity. Display Name - Log WF Completed. Message - “WF Completed”.
  13. Drag and drop the GetCurrentItemId activity to the designer from the toolbox in between the two WriteToHistory activity as shown below.



  14. Select Sequence and click on Variables



  15. In the Variable window click on Create Variable and provide the variable name as currentItemId and set the variable type as Int32.



  16. Again follow Step 14 to remove the Variable window.
  17. Select GetCurrentItemId activity and press F4 to open the properties window and set the Result property as currentItemId.



  18. Drag and drop the WriteToHistory activity. Set the DisplayName as Log Current Item Id and Message as string.Format("Current Item Id : {0}", currentItemId.ToString())
  19. Follow the step 14 and create the variable as historyListId and Select Browse for Type.



  20. In the browse and Select .Net type window type Guid





  21. Click Ok to close the window.
  22. Repeat Steps 19 to 21 and create the variable called taskListId and set the Guid as the variable type.
  23. Again follow the same steps and create a variable called initiator and webUri. Then set the variable type as string for both variables. The final variable window is as below.



  24. Click on variables to close the variable window.
  25. Drag and drop GetHistoryListId to the designer and set the Result property to historyListId.



  26. Drag and drop WriteToHistory activity. Set DisplayName as Log History List Id and Message as:
    1. string.Format("History List Id : {0}", historyListId.ToString()) 
  27. Drag and drop GetTaskListId to the designer and set the Result property to taskListId.



  28. Drag and drop a WriteToHistory activity. Set the DisplayName as Log Task List Id and Message as string.Format("Task List Id : {0}", taskListId.ToString())
  29. Drag and drop a LookupWorkflowContextProperty to the designer and set the PropertyName property as Initiator.



  30. Then set the Result property as initiator.
  31. Drag and drop a WriteToHistory activity. Set the DisplayName as Log WF Initiator and Message as string.Format("WF Initiator : {0}", initiator)
  32. Drag and drop a WebUri activity to the designer and set the Result property to webUri.



  33. Drag and drop a WriteToHistory activity. Set the DisplayName as Log Web Uri and Message as string.Format("Web Uri : {0}", webUri)
  34. Build and deploy the solution.
  35. Open the List page in the SharePoint site to add the new Item.



  36. Click on the (…) and select Workflows and click (WFContextObjects – Workflow Start) on the link to start the workflow.
  37. Again click on the (…) and select workflows and click on Started.
  38. Then you will see the output in the Workflow History.