Search This Blog

Sunday, December 14, 2014

SharePoint Foundation 2010 Visual Studio Approval Workflow

  1. The scenario is that a document library has a column of type option named WorkFlowLevelLevel -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.
    Column
    Approver groups
  2. The final workflow is as below:-
  3. To create such solutions fire up the Visual Studio and select a Sequential Workflow template, and set the solution settings as below
  4. First code is to define the OnWorkflowActivated event .
  5. Then connect this method to the activity on the designer
  6. 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.
  7. 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)
  8. 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
  9. Drop the send email activity and associate the above code.
  10. Now we are going to use the while loop that will loop until the Approve Status is equal to Approved or Reject.
  11. Associate the while loop with the code below
  12. Inside the while loop drop the OnWorkflowItemChanged activity and then define the code before associating the two.
  13. 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.
  14. Below is the email code for sendApprovedEmail
  15. One last part of the workflow is the right hand side, where the document does not require any approvalThe approval status is automatically set to Approved.
  16. For that, just drag and drop the Code activity from the Toolbox inside the else activity and associate the ExecuteCode.
  17. 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).
  18. Oh, by the way the link in the email will open the below page (Item Display Form).
    Ciao..

No comments:

Post a Comment