This article explains how to use the LookupSPList, LookupSPListItem and LookupSPListItemId activities in Visual Studio 2013 for SharePoint 2013 Workflows.
Implementation Procedure
- Open the SharePoint site and create a custom list called “WFSPListObjects”.
- Create New SharePoint 2013 - Empty Project and provide the name as you want.
- Click Ok. In the next window provide the site collection name you want to deploy the project to and choose Sandboxed Solution.
- Click Finish and wait for some time to create the project.
- Add new item as Workflow and provide the name as “WFSPList”.
- In the next window provide the name of the workflow and choose the List Workflow option and click Next.
- Select the List, History List and Task List as shown below.
- Click Next. Leave it as the default selection (A user manually stats workflow option).
- Click Finish. Then you will see the designer screen as below.
- Drag and drop the WriteToHistory Activity to the sequence from the Toolbox as shown below.
- 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.
- Repeat Step 11 for another WriteToHistory activity. Display Name – Log WF Completed. Message – “WF Completed”.
- Select Sequence and click on Variables
- In the Variable window click on Create Variable and provide the variable name as listProperties and set the variable type as Dynamic Value.
- Again follow Step 13 to remove the Variable window.
- Drag and drop the LookupSPList activity (Under SP – List category) between the WriteToHistory activity and set the properties as below.
- Click Get Properties on LookupSPList activity and see that the listProperties variable is set to the source.
- Click "Define…" in the GetDynamicValueProperties and select the entity type as below.
- Double-click on Create Property from the Properties window and Select Title, Created as shown below.
- Click on Populate Variables in the properties window and see the Title and Created Variable in the Assign To Column.
- Drag and drop the WriteToHistory activity and provide the input message as string.Format("List Title : {0}, List Created Date : {1}", Title, Created.ToString())
- Create a new variable called “listItemProperties” and set the variable type as “Dynamic Value”.
- Drag and drop the LookupSPListItem activity to the designer (before Log WF Completed – WriteToHistory activity) and set the properties as below.
- Click Get Properties on LookupSPListItem and click on "Define…" in the GetDynamicValueProperties activity.
- Set the value in the properties window as shown below.
- Entity Type: List Item of WFSPListObjects
- Path: ID, Title
- Click on Populate Variables – Automatically ID and Title1 variable will be created and assigned.
- Drag and drop the WriteToHistory activity and provide the input message as string.Format("List Item ID : {0}, List Item Title : {1}", ID.ToString(), Title1)
- Create a new variable called “listItemID” and set the variable type as “Int32”.
- Drag and drop the LookupSPListItemId activity and set the properties as shown below.
- Drag – WriteToHistory activity. Input Message as : string.Format("List Item Id : {0}", listItemID.ToString())
- Build and deploy the workflow.
- Go to the list URL in the SharePoint site and add a new item.
- Click on (…) and select Workflows as below.
- Click on the link as below.
- Again follow Step 32 and click on started in the next screen.
- Refresh the page for a few seconds and see the output in the workflow history.