SharePoint 2013 - SPLessons

Creating SharePoint 2013 State Machine Workflows in Visual Studio 2012

Home > > Tutorial
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Creating SharePoint 2013 State Machine Workflows in Visual Studio 2012

Creating SharePoint 2013 State Machine Workflows in Visual Studio 2012

Description Hi every one, in our previous article we have implemented single state State machine workflow. Today we are going to learn how to create Three States State machine Workflow in SharePoint. Previous Ref: http://www.splessons.com/2013/12/create-state-machine-workflow-in-sharepoint-2013-using-visual-studio-2012/ Step 1: Please check the previous article there we have explained how to create state machine workflow single state and then use the bellow code for three states workflow. [csharp] public LeaveWorkFlow()         {             InitializeComponent();         }           public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();         public Guid createTask1_TaskId1 = default(System.Guid);         public SPWorkflowTaskProperties createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void createTask1_MethodInvoking(object sender, EventArgs e)         {             createTask1_TaskId1 = Guid.NewGuid();             createTask1_TaskProperties1.Title = "Request For Leave";             createTask1_TaskProperties1.AssignedTo = @"dc\administrator";             }           public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();         public SPWorkflowTaskProperties onTaskChanged1_BeforeProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)         {             onTaskChanged1_AfterProperties1 = onTaskChanged1.AfterProperties;           }           private void LeaveConditionMethod(object sender, ConditionalEventArgs e)         {             if (onTaskChanged1_AfterProperties1.PercentComplete == 1.0)             {                 e.Result = true;             }             else             {                 e.Result = false;             }         }           public Guid TeamLeadCreateTask_TaskId1 = default(System.Guid);         public SPWorkflowTaskProperties TeamLeadCreateTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void TeamLeadCreateTask_MethodInvoking(object sender, EventArgs e)         {               TeamLeadCreateTask_TaskId1 = Guid.NewGuid();             TeamLeadCreateTask_TaskProperties1.Title = "Request For Leave To TeamLead";             TeamLeadCreateTask_TaskProperties1.AssignedTo = @"dc\administrator";         }           public SPWorkflowTaskProperties TeamLeadTaskChanged_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void IfTeamLeadApproved(object sender, ConditionalEventArgs e)         {             if (TeamLeadTaskChanged_AfterProperties1.PercentComplete == 1.0)             {                 e.Result = true;             }             else             {                 e.Result = false;             }         }           private void TeamLeadTaskChanged_Invoked(object sender, ExternalDataEventArgs e)         {             TeamLeadTaskChanged_AfterProperties1 = TeamLeadTaskChanged.AfterProperties;         }           public Guid HRcreateTask_TaskId1 = default(System.Guid);         public SPWorkflowTaskProperties HRcreateTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void HRcreateTask_MethodInvoking(object sender, EventArgs e)         {             HRcreateTask_TaskId1 = Guid.NewGuid();             HRcreateTask_TaskProperties1.Title = "Request For Leave To HR";             HRcreateTask_TaskProperties1.AssignedTo = @"dc\administrator";         }           public SPWorkflowTaskProperties HRTaskChanged_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();           private void HRTaskChanged_Invoked(object sender, ExternalDataEventArgs e)         {             HRTaskChanged_AfterProperties1 = HRTaskChanged.AfterProperties;         }           private void IFHRApprove(object sender, ConditionalEventArgs e)         {             if (HRTaskChanged_AfterProperties1.PercentComplete == 1.0)             {                 e.Result = true;             }             else             {                 e.Result = false;             }           } [/csharp] And then Deploy the soluction Step 2: Go to the sharepoint site and add the item into the sharepoint list(Target List). Step 3: Go to the sharepoint Task list, Here we can see Assign First Task With Not started Status.   then Click on Edit item Button.   Enter % complete Colunm , Because of based on our code  Condition,(if you enter 100% then ,that particular task will assign to the next state ,other wise workflow will complete here like rejected the assigned user). Step 4: Here we can see First Task completed Status  and  Assign Second Task With Not started Status  ,then Click on Edit item Button.   Enter % complete Colunm , Because of based on our code  Condition,(if you enter 100% then ,that particular task will assign to the next state ,other wise workflow will complete here like rejected the assigned user). Step 5: Here we can see Second Task completed Status  and  Assign Third Task With Not started Status  ,then Click on Edit item Button .   Enter % complete Colunm , Because of based on our code  Condition,(if you enter 100% then ,that particular task will assign to the next state ,other wise workflow will  assign to the first State  ). Step 6: Now Three states completed   Then Target list status should be Updated as completed.