- The scenario is that a document library has a column of type option named WorkFlowLevel. Level -0 means that the document is approved automatically by the uploader and Level -1 means the document can only be approved/reject by a person who is in the Approver groups.ColumnApprover groups
- The final workflow is as below:-
- To create such solutions fire up the Visual Studio and select a Sequential Workflow template, and set the solution settings as below
- First code is to define the OnWorkflowActivated event .
- Then connect this method to the activity on the designer
- Next go to the Toolbox, under the Window Workflow v3.0 tab drag and drop the ifElse activity just below the previous activity and then define the code to execute.
- Associate the above code to the left if branch (if the condition return true then this side will fire, if it false the right side will automatically fire)
- If true, the left side will execute a code (see below) that will email a document approval request to all the member of the Approver groups
- Drop the send email activity and associate the above code.
- Now we are going to use the while loop that will loop until the Approve Status is equal to Approved or Reject.
- Associate the while loop with the code below
- Inside the while loop drop the OnWorkflowItemChanged activity and then define the code before associating the two.
- When the document have been approved or rejected, the loop will break where based on the status we will send the email to the document creator. Drop the ifElse activity just below the while loop.
- Below is the email code for sendApprovedEmail
- One last part of the workflow is the right hand side, where the document does not require any approval. The approval status is automatically set to Approved.
- For that, just drag and drop the Code activity from the Toolbox inside the else activity and associate the ExecuteCode.
- To approve a document, the user needs to have at least Design permission level. Even though the workflow can be triggered by user that has permission other than Design which by right the code should be elevated. Here we are not elevating anything since unlike SharePoint Designer workflow which runs under the user
who triggers it, a Visual Studio workflow will always run using the System Account (that means Full Control). - Oh, by the way the link in the email will open the below page (Item Display Form).Ciao..
Search This Blog
Sunday, December 14, 2014
SharePoint Foundation 2010 Visual Studio Approval Workflow
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment