SharePoint 2013 - SPLessons

SharePoint Sequential Worklflow

Home > Lesson > Chapter 58
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SharePoint Sequential Worklflow

SharePoint Sequential Worklflow

A sequential workflow  provides a structured series of steps in which one activity leads to another, and steps generally occur immediately one after another. sequential workflows are often used to model processes that operate without human intervention.

Create a Sequential workflow using Visual Studio

Step 1 

Create "Splessons" List inside SharePoint And Create the Columns as we Required. To create an Empty SharePoint Project
  1.  Start Visual Studio 2012 in administrator mode.
  2. On the File menu, point to New, and then click Project. If Visual Studio is set to use Visual c# development,settings, on the File menu, click New Project.
  3. In the New Project dialog box, select the SharePoint Soluction node.
  4. In the Templates pane, select Empty SharePoint Project. For the name of the project, type Splessons, and then click OK.
It will open the wizard to create the project Select the site where you want to deploy the soluction. and select Deploy as a Farm box solution and click on Finish to create the project On the Project menu, click Add New Item. Select Sequential Worklflow template and name is "SequentialWF" and Click on Add. Select the list workflow and next ,here  the list labeled The library or list to associate your workflow with And Select the Tasks List for Assign the List Item.click Next. On the Specify the conditions for how your workflow is started page, click Finish.

Step 2

Drag and drop CreateTask control in Toolbox to here From the SharePoint Workflow options in the Toolbox, drag a CreateTask activity and add it to the below onWorkflowActiveted  drop area. In the Properties pane, in the CorrelationToken property, type HR, and press Enter. In the Properties pane, expand the  CorrelationToken property, and in the OwnerActivityName list, select ‘SequentialWF’. In the Properties pane, in the TaskID property, click the value, and then click the ellipsis button (…). In the Bind ‘TaskID’ to an activity’s property dialog box, click the Bind to a new member tab. In the Choose the type of member to create option list, click Create Field. Click OK. In the Properties pane, click the TaskProperties property, and then click the ellipsis button (…). In the Bind ‘TaskProperties‘ to an activity’s property dialog box, click the Bind to a new member. In the Choose the type of   member to create option list, click Create Field, and then clickOK. Next, Double click to createTask1 in ‘CreateTaskHr’ [csharp] private void createTaskHr_MethodInvoking(object sender, EventArgs e) { createTaskHr_TaskId1 = Guid.NewGuid(); createTaskHr_TaskProperties.Title = "Request For Leave"; createTaskHr_TaskProperties.AssignedTo = @"dc/Sreehari"; }[/csharp]

Step 3

From the SharePoint Workflow options in the Toolbox, drag an While Condition item to the ‘LeaveprocessState’ drop Activities area. From the SharePoint Workflow options in the Toolbox, drag an onTaskChanged item to the ‘LeaveprocessState’ drop Activities area. In the Properties pane, click the TaskID property, and then click the ellipsis button (…). In the Bind ‘TaskID‘ to an activity’s property dialog box, on the Bind to an existing member tab, click createTaskHr_TaskId1Click OK. In the Properties pane, click the AfterProperties field, and then click the ellipsis button (…). In the Bind ‘AfterProperties‘ to an activity’s property dialog box, click the Bind to a new member tab. In the Choose the type of member to create option list, click Create Field, and then click OK. In the Properties pane, in the CorrelationToken property, select HR. click on  onTaskChanged1_Invoked,Add the following code. [csharp] private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e) { onTaskChanged1_AfterProperties1 = onTaskChanged1.AfterProperties; }[/csharp] Below method for checking the Condition [csharp]private void LeaveConditionMethod(object sender, ConditionalEventArgs e) { if (onTaskChanged1_AfterProperties1.PercentComplete == 1.0) { e.Result = true; } else { e.Result = false; } }[/csharp] Click the Design tab, and then click the While activity. In the Properties pane, click the Condition property, and then select Code Condition in the drop-down list. In the Properties pane, expand the Condition property. In the drop-down list, select ‘LeaveConditionMethod'. Total Workflow code.cs Code [csharp] private void createTaskHr_MethodInvoking(object sender, EventArgs e) { createTaskHr_TaskId1 = Guid.NewGuid(); createTaskHr_TaskProperties.Title = "Request For Leave"; createTaskHr_TaskProperties.AssignedTo = @"dc/Sreehari"; } public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1 = 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; } }[/csharp]

Step 4

To deploy the project In Solution Explorer, right-click the project, and then click Deploy. After Deployed the project Open the SharePoint Site. Now We can check the Flow of the functionality , Add the NewItem into the ‘RequestLeaveForm’ List Click Save Button. After add the Item We will get the result Like below dialog , Check the ‘SequentialWF‘ ColunmNow Our Status is Inprogress. Open the Tasks list, and review the Request For Leave. Edit the Request For Leave. in the Complete % box, type 100. Because based on our condition method ,we need update the columns, Click Save. Here our task list status was updated Open the list‘SplessonsList’ and note that the List Column workflow is completed