Create, Update and Delete List Item Using Builtin Activity in SharePoint 2013 Workflows

This article explains how to Create, Update and Delete a List Item using a builtin activity available in the workflow toolbox for SharePoint 2013 in Visual Studio 2013.

Implementation Procedure

  1.  Create a new Empty SharePoint 2013 Project named CreateUpdateDeletListItem
  2.  Choose Deploy as sandboxed solution in the next screen and click Finish
  3.  Add New Item as Workflow and provide the name as WFCRUDOperation
  4.  In the next window provide the name of the Workflow as “WF CRUD Operation” and select the List Workflow option and click Next.
  5.  In the next window select List, History List and Task List as shown below and click Next.

    Task List

  6.  Leave the default selection (A user manually starts…) and click Finish
  7.  Drag and drop the History Activity and change the display name to “Log WF Started”

    Log WF Started

  8.  Provide the input Message as “WF Started” in the Expression Editor Window.

    Expression Editor Window

  9.  Drag and drop the CreateListItem activity and Set the ListId property to the List you want to insert the new item in.

    CreateListItem

  10.  Click the (…) button next to the ListItemPropertiesDynamic as shown below and provide the value as in the left side window (ListItemPropertiesDynamicValue).

    ListItemPropertiesDynamicValue

  11.  Repeat Step 7 and 8. Provide the Display Name as “Log List Item Creation” and provide the input message as “List Item Created”.
  12.  Drag and drop the Delay Until activity as below.

    Delay Until

  13.  Click on the (…) button next to the Date properties and provide the value as shown below.

    Date properties

  14.  Drag and drop the UpdateListItem activity to the designer as below.

    UpdateListItem

  15.  Click on the (…) button to open the ItemId window and type 1 and click OK.

    ItemId

  16.  Set the ListId property as WFCodeActivityList and check that the WFCodeActivityList contains the ID 1 as below.

    WFCodeActivityList

  17.  Click on the (…) button next to the ListItemPropertiesDynamicValue and provide the value as shown below.

    ListItemPropertiesDynamicValue1

    ListItemPropertiesDynamicValue2

  18.  Drag and drop the WriteToHistory activity and provide the display name as “Log Update Item” and set the message to “Item Updated”.
  19.  Drag and drop the Delay activity and set the date properties to DateTime.UtcNow.AddMinutes(1).
  20.  Drag and drop the DeleteListItem and set the properties as below.

    DeleteListItem

  21.  Ensure that the WFCurrentContext list has the item ID 4 as shown below.

    WFCurrentContext

  22.  Drag and drop the WriteToHistory activity and provide the display name as “Log Delete Item” and set the message as “Item Deleted”.
  23.  Drag and drop the WriteToHistory activity and provide the display name as “Log WF Completed” and set the message as “WF Completed”.
  24.  Build and deploy the application.
  25.  Add the new Item into the List that the workflow is associated as shown below.

    Add new Item

  26.  Click on the (…) and select Workflows from the menu list.

    Workflows

  27. Click on the link.

    New Workflow

  28.  Repeat Step 26 and click on started.

    Running workflow

  29.  Refresh the page and you will see the List Item Created Message will be displayed in the Workflow History.

    List Item Created

  30.  Go to the WFSPLIstObjects List and see that the new item is created.

    WFSPLIstObjects

  31.  Then wait for 2 minutes. In this time Delay the activity will execute.
  32.  Again go the History list page and see the Item Updated Message as below and see the time.

    Workflow histry

  33.  Let go to the WFCodeActivityList and see the Item has been updated by WF.

    WFCodeActivityList

  34.  Then wait for 1 minute. In this time Delay the activity will execute.
  35.  Go to the history page and see the result as shown below.

    history page

  36.  Then go to the WFCurrentContext list and see the output as below.

    WFCurrentContext1