Wednesday, November 21, 2012

Sequential Work Flow in SP 2010 Using VS 2010


Introduction
In this article we will see how to create a sequential work flow in SharePoint 2010 using VS 2010.

Objective
Let's make the scenario simple. We want to create a simple work flow and if the work flow status is not completed, we need to prevent the user from deleting the document.

Steps
First we need to create a "Status" column with a Choice field type with various status options in our Document library.
Sequenceworkflow1.jpg
Once the "Status" column  was created, the document library will be as shown below:
Sequenceworkflow2.jpg

Open the VS2010 -> Select SharePoint 2010 -> Select the Sequential work flow project type and complete the wizard as shown below.
Sequenceworkflow4.jpgSequenceworkflow4.jpgJust click the OnWorkFlowActivated step and create an event called OnWorkFlowActivated_Invoked:Just click the OnWorkFlowActivated step and create an event called OnWorkFlowActivated_Invoked: Just double-click the onWorkflowActivated step. It will redirect to the code behind file.Drag a while loop step from the Tool Box, below the onWorkflowActivated step:Drag a while loop step from the Tool Box, below the onWorkflowActivated step: 
Sequenceworkflow9.jpg Sequenceworkflow11.jpg



Invoke the "IsWorkFlowPending" method in both the "onWorkflowActivated_Invoked" and the "onWorkflowItemChanged1_Invoked" methods.Invoke the "IsWorkFlowPending" method in both the "onWorkflowActivated_Invoked" and the "onWorkflowItemChanged1_Invoked" methods.Let's deploy the solution and we will check whether or not the workflow is deployed in our document library.Let's deploy the solution and we will check whether or not the workflow is deployed in our document library. 

Upload a document and start the workflow: We will see the workflow status as "InProgress" in the document library. Edit the task and change the status to Approved. Our workflow status will change to "Completed". We can prevent the user from "Deleting" the document, if the "Status" is not completed. Just add an Event Receiver in the same work flow project. 







Sequenceworkflow23.jpgLet's check the code in the UI using a document which is in the InProgress Status and try to delete the document.Let's check the code in the UI using a document which is in the InProgress Status and try to delete the document. If we click ok also the document is still in our repository. Let's make some changes in the code to display a user friendly message: Now when we try to delete the document we will see the following message. Summary                We created a simple work flow in VS 2010 and prevent the users from deleting a document, if its not approved.                We created a simple work flow in VS 2010 and prevent the users from deleting a document, if its not approved.
                
We created a simple work flow in VS 2010 and prevent the users from deleting a document, if its not approved.







Sequenceworkflow3.jpg
By default we have the following simple start page:
Sequenceworkflow5.jpg
Sequenceworkflow6.jpg
Sequenceworkflow7.jpg
Sequenceworkflow8.jpg
Select the while loop step and in the property window configure the "Condition" as "Code Condition" and create an event called "IsWorkFlowPending".
Sequenceworkflow10.jpg
Sequenceworkflow12.jpg
Sequenceworkflow13.jpg
Sequenceworkflow14.jpg
Sequenceworkflow15.jpg
Place the following in the our workflow:
Sequenceworkflow16.jpg
Sequenceworkflow17.jpg
Sequenceworkflow18.jpg
Sequenceworkflow19.jpg
Sequenceworkflow20.jpg
Sequenceworkflow21.jpg
Sequenceworkflow22.jpg
In the code behind file, we will prevent the user from deleting a document if the status is "Pending".
Sequenceworkflow24.jpg
Sequenceworkflow25.jpg
Sequenceworkflow26.jpg
Sequenceworkflow27.jpg
Sequenceworkflow28.jpg


Summary



No comments:

Post a Comment