WaitForFieldChange Activity in SharePoint 2013 Workflows

Introduction

This article explains how to use a WaitForFieldChange Activity in SharePoint 2013 Workflows using Visual Studio 2013.

Scenario

Before copying the item into another Document Library wait for some time to change the field value in the Document Library using a WaitForFieldChange activity in SharePoint 2013 workflows.

Step-by-step Implementation

  1. Open a SharePoint site and click on the icon that is available in the right side of the site and click Site Contents from the menu list or click Site Contents from the Quick Launch as shown below.

    Open SharePoint site

  2. Click the add an app icon to create a List or Document Library.

    add an app

  3. From the apps page click Document Library and provide the name as WFDocuments in the TextBox and click Create.

    Click Document Library

    WFDocuments


  4. Repeat Steps 2 & 3 and create the Document Library called WFCopyDocuments.
  5. Click on WFDocuments from the Quick Launch and select LIBRARY from the ribbon control and click on Create Column as shown below.

    click on Create Column

  6. Provide the column name as “Document Status” and choose the type as Choice

    Document Status

  7. Scroll down in the Create Column window and provide the value as Pending, Approved and Rejected as one by one as follows. (Instead of Enter Choice #1, Enter Choice #2…)

    value as Pending

  8. Choose the default value as Pending.

    default value as Pending

  9. Open Visual Studio 2013 and create a new SharePoint 2013 Empty Project and provide the name and click OK.
  10. In the next screen provide the site collection name you want to deploy the solution for and choose Deploy as Sandboxed solution option and click Finish.
  11. Right-click on the project and add New Item as Workflow and provide the name to workflow as WFCopyWaitItem and click the Add button.
  12. In the next screen, provide the name of workflow is WF Copy Wait Item and choose the List Workflow option and click Next.
  13. In the next screen choose Document Library, history list and task list as follows and click Next.

    task list

  14. Select the option of User Manually to start the workflow and click Finish to add it.
  15. Drag and drop two WriteToHistory activities to the designer and provide the display name as “Log WF Started” and “Log Wait…” respectively.
  16. Then provide the message as "WF Started" and "Wait until the field value changed..." respectively.
  17. Drag and drop the WaitForFieldChange activity and set the properties as shown below.

    WaitForFieldChange

  18. Drag and drop a WriteToHistory activity to the designer and provide the display name as “Log Field Changed” and provide the input message as "Field Value Changed. Item going to Copy...".
  19. Drag and drop the CopyItem activity and set the properties as shown below.

    CopyItem

  20. Drag and drop the two WriteToHistory activities and provide the input as "Item Copied to Destination" and "WF Completed" respectively.
  21. Provide the display name as “Log Item Copied” and “Log WF Completed” respectively.
  22. Build and Deploy the Solution.
  23. Open the WFDocuments library page in the site and upload a new document and see the default document status Pending as shown below.

    WFDocuments library page

  24. Click on the (…) and select workflows.

    select workflows

  25. Click the link to start the workflow.

    start the workflow

  26. Again repeat Step 16 and click on Started.

    Again repeat

  27. Then see the workflow history description value as shown below.

    history description

  28. Then go to the WFDocuments library page and select the Edit Properties as below.

    go to the WFDocuments

  29. Then change the value to Approved from Pending and click Save.

    Approved from Pending

  30. Then repeat Step 16 and click on completed.

    repeat the step

  31. Then see the Workflow History list description as follows.


    Workflow History list
  32. Click on WFCopyDocuments Library and see that the uploaded document is copied to the library as shown below.

    WFCopyDocuments