A Workflow Based Solution for SharePoint 2010

Posted by: Mahesh Sabnis , on 10/30/2012, in Category SharePoint
Views: 45111
Abstract: This article demonstrates how SharePoint 2010 can be used to create workflow’s for automating business processes.

Several organizations are using SharePoint based solutions for internal process automation where multiple users collaborate together as a part of the process. One of the natural techniques of any process automation process is use of Workflow. SharePoint has a builtin Workflow Engine. When any SharePoint object like, List, Document library is created; these objects can be managed as per the rules specified in a Workflow.

Workflows associated with a SharePoint site can be created using SharePoint 2010 designer. There are two types of Workflows:

- A Sequential Workflow, this has one start point and then it can be completed successfully or terminated based upon the defined conditions. Sequential Workflow is mostly used for automated processes.

- The second one is the State Machine Workflow, which is purely based upon the state transition methodology. This is an ideal model for more complex business processes where these processes require human intervention at various states. In this workflow, an Initial State and Completion State exists. The execution path from Initial State to End State is completely based upon transition between states and events triggered. In this model, every state can represent a sub-process in the big complex process.

 

The following two diagrams show simple Models for Sequential and State Machine Workflows:

Sequential Workflow:

image

State Machine Workflow:

image

These two diagrams clearly show the Workflow model. The Sequential Workflows are like flowcharts where there is a defined Start and End. Whereas the State Machine starts with an Initial State and there are various transitions based upon triggered events, which determine the path of the workflow.

Typically for SharePoint applications, Workflow instances can be started on the following actions:

  • When document or List Item is created, user can instantiate a workflow manually from the option on the ribbon control.
  • Automatically when the document or List Item is created or changed.

 

Develop Workflow for SharePoint 2010 Applications

Developing Workflow for SharePoint apps is now possible with SharePoint Designer 2010 (SPD) and also with Visual Studio (VS) 2010. The workflow designed using SPD can be imported in VS and be changed. In this article, I am going to explain mechanism of developing a Workflow using SPD. SPD provides workflow editor and workflow settings to create and configure workflow. The Workflow editor works within the scope of the SharePoint site. To create a workflow, you must have enough access rights on the particular site. Following are the categories offered by SPD for workflow creations:

image

Creating List in SharePoint 2010

For this article, we will be using a simple scenario of Patient Admission process in a hospital having a Diseases department. The Workflow generates the doctor and registration fees based upon the admission category e.g. Cancer, Cardio, and Orthopedic etc.

We already have the Site created at the URL hxxp://intranetMyHospital.com/Sites/MISPortal [replace hxxp with http]. We will start creating a List and then we will attach the workflow to it.

Task 1: Visit the URL in the browser and click on the Lists on the Left side panel

Task 2: A new Page with ‘All Site Contents’, shows up. Click on Create

Task 3: Select the ‘Filter By’ as ‘List’ and then select ‘Custom List’. Set the name as ‘Patient Category Admit’. This List will contain information of Patients and based upon the Category of the Admit (e.g. Cancer, Cardio), the associated workflow will return Doctor Fees and Registration Fees information.

Task 4: The Workflow which is to be associated with the List, may be imported in Visual Studio for further modification in future. To do this, we need to create ‘Reusable Workflow’. A Reusable workflow requires ‘Site Columns’ for defining rules. So we will define site columns next. Go to Site Settings and select ‘Site Columns’ from Galleries as shown below:

image

 

The reason we are using ‘Site columns’ is in Hospital Automation, we will need the Admission category for the patient across multiple functions, e.g. various fees etc.

To add Site Columns, use the ‘Site Columns’ shortcut on the ribbon. Click on ‘Create’ to get to the ‘New Site Column’ page where we can enter information like, Column Name, its Type

  • Set ‘Column Name’ as ‘Patient Disease Dept.’
  • Select ‘Type’ as ‘Choice’
  • Make it mandatory by selecting ‘Yes’ for the ‘Require that this column contains information’ setting.
  • Set it to non-Unique by selecting ‘No’ for the ‘Enforce unique value’ field.
  • Add choice values of the following (one in each line)
    Cancer
    Cardio
    Orthopedic
    Eye


Now create two more Custom Columns - ‘Doctor Fees’ and ‘Registration Fees’. Set their type to Numeric. You can see the site columns created on the ‘Site Column’ page as below:

image

Task 5: To create rest of the columns for the List, click on the ‘Patient Admin Category’ List on the Left Panel, you will get the List Details, select ‘List Settings’:

Task 6: Create columns using ‘Create Column’ Link

Task 7: Since we have already created site columns, to add them in this list, click on ‘Add from existing site columns’. You will get the Page where all site columns are specified, you can select site columns from the available site columns. Add the ‘Patient Disease Dept.’, ‘Doctor Frees’ and ‘Registration Fees’ from the Available site Columns.

 

image

Now the complete List will have the following columns:


- Title
- Patient ID
- Patient Home
- Patient Disease Dept.
- Doctor Fees
- Registration Fees
- Created By
- Modified By


 

Creating Workflow using SharePoint Designer 2010

Task 1: Open SPD and open the SharePoint portal where you have the List. You will find all the Portal objects. Select the Workflow from the Panel as shown here:

image

Task 2: We need to create a Reusable workflow, so click on the ‘Reusable Workflow’ from the Ribbon as shown below:

image

Set the workflow name and its description as follows:

Name: Patient Category Workflow
Description: The Workflow is used to define the Rules for Admitting Patient in Hospital in a specific Department.

You will see the Workflow Designer as shown here:

image

The workflow designer shows ‘Workflow’ ribbon which provides various features listed here:


• Save: The workflow is saved in the XOML file, this allows us to export file to Visual Studio.
• Publish: This publishes workflow which is then available in the SPS portal and you can associate with the SharePoint objects.
• Check for errors: This checks any problem with workflow. It is strongly recommended that you should check for errors before publishing.
• Condition: This provides various conditions to be put in workflow e.g. if-else.
• Action: Provides the mechanism of steps to be taken when the condition is evaluated.
• Publish Globally: This allows workflow to be published on the Global Workflow Catalog so that it can be available to all SharePoint Sites.
• Export to Visio: Export the workflow to the Vision 2010 premium.
• Workflow Settings: Define the workflow settings for specifying the behavior the Workflow e.g. Auto start or manual start of the Workflow.

Task 3: In the reusable workflow, we require the Site columns to be associated for defining conditions. To do this, select ‘Association Columns’

Now add the Association site columns as shown below:

image

Task 4: Drag-Drop the ‘if’ condition from the Action Pane of the Ribbon as below:

image

You will get a condition:

image

Here the ‘field’ represents the Column from the List (or site column) on which the condition is defined and the ‘value’ represents the condition evaluation expression. Since this workflow defines rules for ‘Patient Diseases Dept.’, if you click on the field, you will get the List of fields for a given condition

image

If you click on ‘value’, you will see the values which we have set for the ‘Patient Diseases Dept.’ site column in previous List Creation steps e.g. Cancer, Cardio etc. Since we have ‘and’ condition for getting Doctor Fees and Registration Fees, we need to have both statement to run in Parallel so below the ‘If’ drag drop, the parallel block is as below:

image

The ‘if’ condition now gets displayed:

image

Put the set statement inside the ‘Parallel’ block as below:

image

You will get the ‘Set’ statement as below:

image

Set rule for the set statement as shown below:

image

Drag-Drop one more ‘Set Field in Current Item’ from the Action of the Ribbon inside the Parallel Block, and set value for Registration Fees.

Task 5: Repeat Task 4 for all condition like Cardio, Orthopedic, etc. The workflow design will be as shown here:

image

image

Task 6: Save and publish the workflow.

Associating the Workflow with the List in the SharePoint Portal

Now it’s time for us to associate the workflow with the List created in previous steps.

Task 1: Go back to the portal, click on the ‘Patient Admit Category’ List, from the ‘List tools’, select ‘List’, and from the ribbon, select ‘Workflow Settings’ as shown below:

image

Select ‘Add a Workflow’ from the options, and you will get an ‘Add Workflow’ Page. Select the ‘Patient Category Workflow’ from the Workflow List and set its unique name to – ‘Patient Category Workflow Status’

Set the Workflow Start Options as shown below:

image

Here the start options are set to ‘Start this workflow when a new item is created’ and ‘Start this workflow when an item is changed’. This means that the moment any new entry is created or updated from the List. Once you click on ‘Ok’ you will get the Workflow Settings page

Task 2: Now add a new entry in the List, the Workflow status against the entry will show ‘In Progress’.

Task 3: Refresh the Page and the Workflow status will be shown as ‘Completed’.

Exporting the Workflow to Visio Premium 2010

We can see the diagrammatic representation of the above created Workflow in SPD by exporting it into Visio Premium.

Task 1: Start SPD and open the Workflow created above. Select Export to Visio from the ‘ribbon’. It will ask you to provide the export name; the file will be saved as ‘Visio Workflow Interchanged File’.

Task 2: Open Visio and create a new ‘Microsoft SharePoint Workflow’. You will get Shapes. Now click on the ‘Process’ menu and select ‘Import’ as below:

image

Select the file which is exported in Task 1, the workflow will be as shown below:

image


 

Conclusion

In SharePoint, workflow provides a powerful mechanism for automation of business processes. SharePoint Designer is a handy tool provided to developers for designing and publishing the Workflow. Apart from automated calculations as seen in this article, we can use Workflows for document approval in various departments where various stake holders can be setup as approvers as a part of a list to which if a document is attached, all users get a chance to approve and add comments.

A flexible workflow engine like the one in SharePoint 2010 gives an added dimension to the other collaboration features it has and makes it a very powerful intranet platform

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Mahesh Sabnis is a DotNetCurry author and a Microsoft MVP having over two decades of experience in IT education and development. He is a Microsoft Certified Trainer (MCT) since 2005 and has conducted various Corporate Training programs for .NET Technologies (all versions), and Front-end technologies like Angular and React. Follow him on twitter @maheshdotnet or connect with him on LinkedIn


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!