This article explains how to use create, update, delete and copy an Item activity that is available in the Workflow Toolbox to create and update an existing item or to delete and copy an item from one document to another in the Document Library in a SharePoint List using Visual Studio 2010.
Part 1: Create Item Activity in SharePoint 2010 Workflow
In this part , I will explain how to use the Create Item Activity available in the Workflow Toolbox to create a new item in a SharePoint List using Visual Studio 2010.
Step-by-step Implementation
Step-by-step Implementation
- Create a Custom List in the SharePoint site as WFCreateItem
- Create an Empty SharePoint project in Visual Studio 2010 and provide the name as CreateItemActivity and click OK.
- In the next screen provide the site collection URL and choose Deploy as Farm solution and click Finish.
- Right-click on the project and add new item as Sequential Workflow and provide the name as WFCreateItemActivity
- Click the Add button and provide the name as WF Create Item Activity and choose List Workflow option as shown below.
- Click Next and associate the list to WFCreateItem that we created in Step 1.
- Click Next and unselect the first option as below and click Finish.
- Then you will see the Workflow Designer screen as below.
- Select onWorkflowActivated1 activity and press F4 to open the properties and change the name to onWFActivated.
- Drag and drop LogToHistoryListActivity to the designer and change the name as logWFStarted in the properties window.
- Then set the History Description property as WF Started.
- Drag and drop the Apply Activation control into the workflow designer after logWFStarted activity and do the procedure below (apply the activation activity that will initialize the workflow context object and then bind into the __Context property of ItemActivity).
- Change the name to applyActivation
- Bind a new property to the __Context property. Click on the button next to the __Context property and select the new member tab and create the variable called workflowContext.
- Bind the existing property to __WorkflowProperties. Click on the button next to the __WorkflowProperties and select the existing member tab and select workflowProperties as shown below.
- Check the final properties screen as below.
- Drag and drop the CreateItemActivity to the designer from the toolbox and provide the name as createNewItem.
- Bind the __Context property to the existing workflowContext property as shown below.
- Then Bind the ListId property to the ListId property of workflowContext as shown below.
- Select ItemProperties from the properties window for the createNewItem activity.
- Right-click on CreateItemActivity and select “Bind Property ItemProperties…” and create a new member as itemProperties.
- Drag and drop 2 LogToHistoryActivities to the designer and provide the name as logItemCreated and logWFCompleted respectively. Then provide the History Description as New Item Added Using WF and WF Completed respectively.
- Then the final UI is as below.
- Right-click on the onWFActivated activity and select Generate Handlers as shown below.
- Add the following code inside the method:
- Change the feature name to WFCreateItemActivityFeature and provide the description as shown below.
- Build and deploy the project.
- Go to the SharePoint site and navigate to the list that you have deployed the project.
- Add a new item to the list and see that the new item has been created as shown below.
- Click on Completed and you will see the workflow history as shown below.
Part 2: Update Item Activity in SharePoint 2010 Workflow
In this part I will explain how to use update an Item Activity that is available in the Workflow Toolbox to update an existing item in a SharePoint List using Visual Studio 2010.
Step-by-step Implementation
In this part I will explain how to use update an Item Activity that is available in the Workflow Toolbox to update an existing item in a SharePoint List using Visual Studio 2010.
Step-by-step Implementation
- Create a Custom List in a SharePoint site as WFUpdateItem.
- Create an empty SharePoint project in Visual Studio 2010 and provide the name as UpdateItemActivity and click OK.
- In the next screen provide the site collection URL and choose Deploy as Farm solution and click Finish.
- Right-click on the project and add a new item as Sequential Workflow and provide the name as WFUpdateItemActivity.
- Click the Add button and provide the name as WF Update Item Activity and choose the List Workflow option as shown below.
- Click Next and associate the list to WFUpdateItem that we created in Step 1.
- Click Next and unselect the first option as below and click Finish.
- Then you will see the Workflow Designer screen as below.
- Select the onWorkflowActivated1 activity and press F4 to open the properties and change the name to onWFActivated.
- Drag and drop LogToHistoryListActivity to the designer and change the name to logWFStarted in the properties window.
- Then set the History Description property to WF Started.
- Drag and drop the Apply Activation control into the Workflow Designer after the logWFStarted activity and do the procedure below (apply the activation activity will initialize the workflow context object and then bind into __Context property of ItemActivity).
- Change the name to applyActivation
- Bind a new property to the __Context property. Click on the button next to the __Context property and select the new member tab and create the variable called workflowContext.
- Bind the existing property to __WorkflowProperties. Click on the button next to the __WorkflowProperties and select the existing member tab and select workflowProperties as shown below.
- Check the final properties screen as below.
- Drag and drop the UpdateItemActivity to the designer from the toolbox and provide the name as updateExistingItem
- Bind the __Context property to the existing workflowContext property as shown below.
- Then Bind the ListId property to the ListId property of workflowContext as shown below.
- Select ItemProperties from the properties window for updateExistingItem activity.
- Right-click on UpdateItemActivity and select “Bind Property ItemProperties…” and create a new member as itemProperties.
- Bind a new property to the ListItem property. Click on the button next to the ListItem property and select the new member tab and create the variable called listItem.
- Drag and drop 2 LogToHistoryActivity to the designer and provide the name as logItemUpdated and logWFCompleted respectively. Then provide the History Description as Item Updated Using WF and WF Completed respectively.
- Then the final UI as below.
- Right-click on the onWFActivated activity and select Generate Handlers as shown below.
- Add the following code inside the method.
- Change the feature name as WFUpdateItemActivityFeature and provide the description as shown below.
- Build and deploy the project.
- Go to the SharePoint site and navigate to the list that you have deployed the project.
- Add a new item to the list as shown below.
- Then refresh the page to see that the list item has been updated as shown below.
- Click on Completed and you will see the workflow history as shown below.
Part 3: Delete Item Activity in SharePoint 2010 Workflow
In this part, I will explain how to use Delete Item Activity that is available in Workflow Toolbox to delete existing item in a SharePoint List using Visual Studio 2010.
Step-by-step Implementation
In this part, I will explain how to use Delete Item Activity that is available in Workflow Toolbox to delete existing item in a SharePoint List using Visual Studio 2010.
Step-by-step Implementation
- Create a Custom List in a SharePoint site as WFDeleteItem and WFListItems.
- Add some dummy data in the WFListItems list as shown below. Change the view with ID.
- Create an Empty SharePoint project in Visual Studio 2010 and provide the name as DeleteItemActivity and click OK.
- In the next screen provide the site collection URL and choose Deploy as Farm solution and click Finish.
- Right-click on the project and add a new item as Sequential Workflow and provide the name as WFDeleteItemActivity.
- Click the Add button and provide the name as WF Delete Item Activity and choose List Workflow option as shown below.
- Click Next and associate the list to WFDeleteItem that we created in Step 1.
- Click Next and unselect the first option as below and click Finish.
- Then you will see the Workflow Designer screen as below.
- Select the onWorkflowActivated1 activity and press F4 to open the properties and change the name to onWFActivated.
- Drag and drop LogToHistoryListActivity to the designer and change the name as logWFStarted in the properties window.
- Then set the History Description property as WF Started.
- Drag and drop the Apply Activation control into the workflow designer after the logWFStarted activity and do the procedure below (apply the activation activity will initialize the workflow context object and then bind into the __Context property of ItemActivity).
- Change the name to applyActivation.
- Bind a new property to the __Context property. Click on the button next to the __Context property and select the new member tab and create the variable called workflowContext.
- Bind the existing property to __WorkflowProperties. Click on the button next to the __WorkflowProperties and select the existing member tab and select workflowProperties as shown below.
- Check the final properties screen as below.
- Drag and drop the DeleteItemActivity to the designer from the toolbox and provide the name as deleteExistingItem.
- Bind the __Context property to an existing workflowContext property as shown below.
- Bind a new property to the ListId property. Click on the button next to the ListId property and select the new member tab and create the variable called ListId.
- Bind a new property to the ListItem property. Click on the button next to the ListItem property and select the new member tab and create the variable called listItem.
- Drag and drop 2 LogToHistoryActivities to the designer and provide the name as logItemDeleted and logWFCompleted respectively. Then provide the History Description as Item Deleted Using WF and WF Completed respectively.
- Then the final UI is as below.
- Right-click on the onWFActivated activity and select Generate Handlers as shown below.
- Add the following code inside the method:
- Change the feature name WFDeleteItemActivityFeature and provide the description as shown below.
- Build and deploy the project.
- Go to the SharePoint site and navigate to the list that you have deployed the project.
- Add a new item to the list.
- Then refresh the page and you will see the output as shown below.
- Click on Completed and you will see the workflow history as shown below.
- Click on the WFListItems list and see the item that has the ID 4 has been deleted from the list.
Part 4: Copy Item Activity in SharePoint 2010 Workflow
In this part, I will explain how to use Copy Item Activity that is available in Workflow Toolbox to copy an item from one document to another Document Library using Visual Studio 2010.
Step-by-step Implementation
In this part, I will explain how to use Copy Item Activity that is available in Workflow Toolbox to copy an item from one document to another Document Library using Visual Studio 2010.
Step-by-step Implementation
- Create a Document Library in the SharePoint site as WF Documents and Client Documents.
- Create an empty SharePoint project in Visual Studio 2010 and provide the name as CopyItemActivity and click OK.
- In the next screen provide the site collection URL and choose Deploy as Farm solution and click Finish.
- Right-click on the project and add a new Sequential Workflow item and provide the name as WFCopyItemActivity.
- Click the Add button and provide the name as WF Copy Item Activity and choose List Workflow option as shown below.
- Click Next and associate the list to WF Documents that we created in Step 1.
- Click Next and unselect the first option as below and click Finish.
- Then you will see the Workflow Designer screen as below.
- Select the onWorkflowActivated1 activity and press F4 to open the properties and change the name to onWFActivated.
- Drag and drop LogToHistoryListActivity to the designer and change the name to logWFStarted in the properties window.
- Then set the History Description property as WF Started.
- Drag and drop the Apply Activation control into the Workflow Designer after the logWFStarted activity and do the procedure below (apply the activation activity will initialize the workflow context object and then bind into the __Context property of ItemActivity).
- Change the name to applyActivation.
- Bind a new property to the __Context property. Click on the button next to the __Context property and select the new member tab and create the variable called workflowContext.
- Bind the existing property to __WorkflowProperties. Click on the button next to the __WorkflowProperties and select the existing member tab and select workflowProperties as shown below.
- Check the final properties screen as below.
- Drag and drop the CopyItemActivity to the designer from the toolbox and provide the name as copyItemToLibrary.
- Bind the __Context property to an existing workflowContext property as shown below.
- Bind the ListId property to the ListId property of workflowContext as shown below:
- Bind a new property to the ListItem property. Click on the button next to the ListItem property and select the new member tab and create the variable called listItem.
- Bind a new property to the ToListId property. Click on the button next to the ToListId property and select the new member tab and create the variable called listId.
- Drag and drop 2 LogToHistoryActivities to the designer and provide the name as logItemCopied and logWFCompleted respectively. Then provide the History Description as Item Copied to Destination Using WF and WF Completed respectively.
- Then the final UI is as below.
- Right-click on the onWFActivated activity and select Generate Handlers as shown below.
- Add the following code inside the method:
- Change the feature name to WFCopyItemActivityFeature and provide the description as shown below.
- Build and deploy the project.
- Go to the SharePoint site and navigate to the library that you have deployed the project.
- Upload a new document to the library.
- Then refresh the page and you will see the output as shown below.
- Click on Completed and you will see the workflow history as shown below.
- Click on the Client Documents library and see that the file is successfully uploaded to the library.
- That's all.
No comments:
Post a Comment