Creating a custom sequential workflow similar with SharePoint OOTB Approval workflow (1) Association / Initiation Form
Creating a custom sequential workflow similar with SharePoint OOTB Approval workflow (2) Custom Activity, While Activity and Replicator Activity
Creating a custom sequential workflow similar with SharePoint OOTB Approval workflow (3) custom Content Type and custom Task Edit Form
Creating a custom sequential workflow similar with SharePoint OOTB approval workflow (4) End on first rejection
Creating a custom sequential workflow similar with SharePoint OOTB approval workflow (5) cancel task(s) when item changed
Creating a custom sequential workflow similar with SharePoint OOTB approval workflow (6) reassign task and request change
a. Add two custom statuses: Approved/Rejected to the workflow, and show these statuses on workflow host list item.
Workflow has some built in statuses like, “In Progress”, “Failed on Start”, “Error Occurred”, etc. In our approval workflow, we need two more custom statuses: Approved/Rejected.
Work on Visual Studio workflow Elements.xml file; add following code just above the ending “Metadata” xml node
<ExtendedStatusColumnValues>
<StatusColumnValue>Approved</StatusColumnValue>
<StatusColumnValue>Rejected</StatusColumnValue>
</ExtendedStatusColumnValues>
Next step we will see the code in Set State activity to assign and show these statuses on workflow host list.
b. Automatically end the workflow if it is rejected by any participant.
After first rejection, stop the Replicator Activity by it’s until condition, also stop the While Activity by its code condition.
We need to add UpdateAllTasks and SetState activities to the workflow to set statuses as following:
Following are the code in these two activities’ Method Invoking event handler:
private void updateAllTasks1_MethodInvoking(object sender, EventArgs e)
{
updateAllTasks1_TaskProperties1.PercentComplete = 1.0f;
updateAllTasks1_TaskProperties1.ExtendedProperties["Status"] = "Completed";
updateAllTasks1_TaskProperties1.ExtendedProperties[SPBuiltInFieldId.WorkflowOutcome] = "Canceled";
private void setState1_MethodInvoking(object sender, EventArgs e)
{
if (Approved)
{
setState1.State = (Int32)SPWorkflowStatus.Max;
}
else
{
setState1.State = (Int32)SPWorkflowStatus.Max + 1;
}
}
c. Keep the originally completed task statuses.
UpdateAllTasks Activity will update all the tasks’ status, but we need to keep the originally completed task statuses.
To do this, add following attribute in front of the custom activity described in Creating a custom sequential workflow similar with SharePoint OOTB Approval workflow (2) Custom Activity, While Activity and Replicator Activity:
[Designer(typeof(ActivityDesigner), typeof(IDesigner))]
[PersistOnClose]
public partial class SPTaskActivity : SequenceActivity
}
After all of above steps, when first rejection, the workflow is rejected, in serial mode, the rest of the approvers are not coming up; in parallel mode, the rest of the approver's status becomes canceled.
No comments:
Post a Comment