Requirement: Create workflow send document from admin to client => client will check validation, if document is not valid, system automatic feedback to admin then admin edit and send to client ... When client check and comment is Approved => workflow completed.
Open Visual studio 2010 | New Project | Expand Visual C# | Sharepoint | 2010 | choose State Machine Workflow template and name is StateMachineWorkflow
Next, UI follows as then drag and drop SetState control in Toolbox to panel State Machine Workflow follows as:
Next, Right click to createTask1 | Properties | In CorrelationToken enter InProcessToken then Expand it, at OwnerActivityName choose stateInProcess from dropdownlist
createTask1_TaskId1 = Guid.NewGuid();
createTask1_TaskProperties1.Title = "Finish Document";
createTask1_TaskProperties1.AssignedTo = @"quochung-axioo\admin";
createTask1_TaskProperties1.DueDate = DateTime.Now.AddDays(1.0);
Click to tab Workflow1.cs[Design] then click Workflow1 follows as:
Next, UI follows as then drag and drop OnTaskChanged control in Toolbox panel State Machine Workflow follows as:
Next, set CorrelationToken is InProcessToken from Dropdownlist then expand it and set OwnerActivityName is stateInProcess
onTaskChanged1_AfterProperties1 = onTaskChanged1.AfterProperties;
onTaskChanged1_BeforeProperties1 = onTaskChanged1.BeforeProperties;
Next, drag and drop IfElse control in Toolbox to below onTaskChanged1 follows as:
private void ReadyForReview(object sender, ConditionalEventArgs e)
{
if (onTaskChanged1_AfterProperties1.PercentComplete == 1.0)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
Right click to ifElseBranchActivity1 and set Condition is Code Condition then expand Condition and at sub Condition choose method ReadyForReview from dropdownlist
Next, Right click to createTask2 | Properties | In CorrelationToken enter ReviewStateToken then Expand it, at OwnerActivityName choose stateReview from dropdownlist
createReviewTask_TaskId1 = Guid.NewGuid();
createReviewTask_TaskProperties1.Title = "Review Document";
createReviewTask_TaskProperties1.AssignedTo = @"quochung-axioo\client";
createReviewTask_TaskProperties1.DueDate = DateTime.Now.AddDays(1.0);
Click to tab Workflow1.cs[Design] then click Workflow1 follows as:
Next, Right click to OnTaskChanged2 | Properties |, set CorrelationToken is ReviewStateToken from Dropdownlist then expand it and set OwnerActivityName is stateReview
Next, set TaskId by click button … follows as
onTaskChanged2_AfterProperties1 = onTaskChanged2.AfterProperties;
onTaskChanged2_BeforeProperties1 = onTaskChanged2.BeforeProperties;
Next, drag and drop IfElse control in Toolbox to below onTaskChanged2 follows as:
private void ReviewFinished(object sender, ConditionalEventArgs e)
{
if (onTaskChanged2_AfterProperties1.PercentComplete == 1.0)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
Right click to ifElseBranchActivity3 and set Condition is Code Condition then expand Condition and at sub Condition choose method ReviewFinished from dropdownlist
Next, click tab Workflow1.cs (code) and paste code to here
{
if (onTaskChanged2_AfterProperties1.Description == "<DIV>Approved</DIV>")
{
e.Result = true;
}
else
{
e.Result = false;
}
}
Right click to ifElseBranchActivity5 and set Condition is Code Condition then expand Condition and at sub Condition choose method DocApproved from dropdownlist
Next, UI as follows then drag and drop SetState control in Toolbox to below ifElseBranchActivity5 follows as:
Next, UI as follows then drag and drop SetState control in Toolbox to below ifElseBranchActivity6 follows as:
Open your site | Click Shared Documents and add any document
Next, enter % Complete is 100, special when comment is “Approved” in Description is workflow completed
Read it:
The State Machine Workflow project in Visual Studio 2010 provides a graphical design surface in which a workflow can be built.
· The Initial State has one activity of SetState that takes the workflow directly to the stateInProgress state.
· The stateInProgress state has a task activity that generates a new task titled "Finish Document" and assigns the task to a specified user.
· The stateInProgress state has an onTaskChanged activity that is invoked when the task changes. TheinTaskChanged activity has an IfElse statement that compares the "percent complete" of the task to 1.0 (100%).
· If the condition is true, the workflow transitions to the next state (stateReview). If it is false, the workflow remains at this state.
· In the stateReview state, a task is generated with a title of "Review Document" as part of the state initialization, and again this task is assigned to a specified user.
· The stateReview state is invoked when the task changes, and an IfElse statement compares the "percent complete" of this task with 100 percent. As before, when the task is 100 percent complete, the workflow continues.
· When the task is 100 percent complete, a nested IfElse statement is reached within the stateReviewstate. The code compares the text that appears in the task description to the string "<DIV>Approved</DIV>".
· If the string matches, the stage is considered complete and the workflow continues to StateFinished. If the string does not match, the state returns to stateInProgress.
Great Blog exactly what i wanted !!!Dude u rock~!!!!!!! :))))
ReplyDeleteI am looking for and I love to post a comment that "The content of your post is awesome" Great work! imprest amount
ReplyDeleteI am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. and Subscribers Views Buy YouTube
ReplyDeleteA very awesome blog post. buy Instagram followers
ReplyDelete