Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Posts Tagged ‘workflow’

Three-state Workflow with Email Notification

Posted by JP on October 14, 2012

In this article we can explore the Three-state workflow of SharePoint 2010. Please note that this is an Out-of-the-box workflow also known as Built-in workflow.

image

Pre-Requisite

For viewing the email notifications generated by the workflow, you need to configure Development Machine with SMTP receiver tool.  Please view the following article to configure email.

Email

What is the purpose of Three-state workflow?

The three-state workflow can be used to track status of list items. There are 3 States involved in the whole process.  For each state change there will be Email Notification performed by this workflow.

For example, we can use this workflow to:

  1. Track Project Tasks
  2. Track Product Issues
  3. Track Reimbursement Reports

The Issue Tracking template of SharePoint is built to work with this workflow as it contains a Choice column with 3 different states.

Exploring the Workflow

For starting with create a new list using the Issue Tracking template as shown below:

clip_image002

After creating the list we need to Associate workflow with the list using List tab > Workflow Settings> Add a Workflow.

clip_image003

A wizard page will be started as shown below.

clip_image004

Select the Three-state workflow and enter a unique name for the workflow. In the bottom of the page you can see the Start Options. Check the Start this workflow when an item is created check box.

clip_image006

Click the Next button to continue.

Now you will be prompted with the second page of the Workflow as shown below:

clip_image008

Please note that the Three-state workflow requires a column with 3 states as the ‘Choice’ field. In this list the Issue Status column is selected as the ‘Choice’ field. The rest 3 drop down lists show the 3 different value selections for the Issue Status to set the Active / Resolved / Closed states.

Coming down to the page you can set Emailing options like Task Information, Email Subject and Body etc. Email Notifications are done to the involved persons.

clip_image010

Leave the default options and click the OK button.Now your workflow is ready to send email notifications on task creation.


Email Notification

For viewing the emails generated by the workflow you need to have:

· Emails Server configured in Central Administration

· E-mail Property set in User Profile

· Smtp4dev tool running

Please view the following article to configure email.

· Configuring Email for Development Server

Testing Workflow

Now let us test the workflow by creating a task. Create a Task and make sure you select a valid user having email for the Assigned To column.

clip_image012

Save the changes and you should see the smtp4dev tool caught the email as shown below.

clip_image014

You can see that the IDvalue is being highlighted. This concludes our experiment with Three-state workflow.

Editing the Workflow

We can associate multiple workflows with a list or library. To edit an existing association use the Workflow Settings > Workflow Settings menu item.

clip_image015

In the appearing page you can view the existing workflows associated and edit the settings.

clip_image017

The Workflows in Progress column displays the number of workflow instances currently active.

There are additional links to Add / Remove workflows, View workflow reports too.

Where should I apply this Workflow?

We can use this workflow for the following requirement scenarios:

· Product or Project approval process where a new product idea can be traversed through different stages of approval before acceptance.

· Issue tracking system where a customer can create an issue item, the support team updates it to resolved, Customer can change the status to Closed or Active again.

· Bug tracking system where the QA can create a task item, developer can change it to Resolved, QA can reopen it.

The effective use of Three-state workflow should decrease the delivery time for a tracking system with email notifications. We can also use custom lists with transition properties for using the Three-state workflow.

Advantage

This workflow provides a quick solution for the state tracking scenario.

image

Otherwise, the same functionality requires multiple days of development with state, email integration, deployment & management hassles.  Thanks to SharePoint as it gives us the same functionality in minutes. 🙂

References

http://tinyurl.com/sp2010-3statwf

Summary

In this article we had explored the Three-state workflow of SharePoint 2010. Following are the point’s worth to be summarized:

· Three-state workflow tracks status changes

· A Choice column is required for the list / library to use this Workflow

· Choice column requires at least 3 fields

· Issue Tracking list template is apt for this workflow

· Association of Three-state workflow with list instance is required

· Email notification is enabled for Three-state workflow

Advertisements

Posted in SharePoint | Tagged: , , , , | 2 Comments »

Delete an Orphaned Workflow

Posted by JP on August 24, 2012

In this article we can explore a real world scenario where a workflow is sending reminder email to users and the interesting thing is that the task list & data no long exists.

I have encountered such scenarios multiple times in my consulting arena and I would recommend running the latest cumulative updates to resolve the issue. In cases where the update patching is not feasible you can use the following solution approach.

Understanding the Problem

To make sure the problem is being conveyed correctly I am using the following points:

1. Task List named Approval List was created

2. A new item was added to the Task List

3. An Approver is being notified on the task

4. The Task List was deleted, removed from Recycle Bin too

5. The notification mail is being sent every week

6. The user cannot modify the task or approve it to stop the emails

This case can arise due to an incomplete migration where the relational columns are mismatched. Our focus is to fix the problem so that our user is not being disturbed by obsolete or invalid emails.


Examining the Problem

As the first step you can try to impersonate as the user into the SharePoint web application. If you cannot access the user credentials you can try examining the SharePoint content database. The content database contains the list, list records, user, work flow information for a SharePoint web application.

You can get the content database name of the web application from Central Administration.

clip_image001

You can see the content database name from the appearing page. Ensure that you are referring to the right web application.

clip_image003

You can click on the Database Name link to see more information about like Server Name.

clip_image005

Now you can try logging in to the database using SQL Server Management. Following are our tables of interest. (Here we are examining List Workflows)

Table

Description

AllLists

This table contains the list metadata like Title, Description etc.

AllUserData

This table contains the user data like list item.

Workflow

This table contains the workflow instances.

Please note that there are no referential constraints but GUID values are used to interconnect between tables. Following are the table structures:

clip_image007

Note: Modification to the table using SQL / Direct Editing is restricted by Microsoft. You should use the Server Object Model for any modifications.

Proposed Solution

The advisable solution is to terminate the workflow using the SharePoint user interface.

To achieve this open Lists > Site Workflows link.

clip_image009

Click on the highlighted link as shown above. You should get the following Workflow Information page.

clip_image011

Click on the Terminate this workflow now link as shown above.

If the workflow gets terminated then you are good. Your customer should be happy as he will be free from the wrong email alert.

You can verify the database record to ensure the InternalStatus column is set to 8.

clip_image012

The enumeration for Internal State column mapping to SPWorkflowState is given below:

clip_image014

Extended Proposed Solution

This solution involves much more effort and advisable if the User or Administrator is not able to perform the above. You can write a piece of code to fetch the workflows under running state and cancel it using the Server Object Model.

Step 1: Create a new windows application

Create a new windows application and make the .Net version to 3.5, Platform Target to Any CPU. Add 1 TextBox, 2 Button and 1 ListBox as shown below:

clip_image016

Step 2: List the Workflow Instances

On the Find Running Workflow button click event invoke the following method which list all the Workflow Instances.

private void RefreshList()

{

using (SPSite site = new SPSite(UrlText.Text))

{

using (SPWeb web = site.OpenWeb())

{

List.Items.Clear();

_internalList = new List<SPWorkflow>();

foreach (SPWorkflow workflow in web.Workflows)

{

List.Items.Add(workflow.AuthorUser.LoginName + " " + workflow.InternalState.ToString() + " " + workflow.Created.ToShortDateString() + " " + workflow.StatusUrl);

_internalList.Add(workflow);

}

}

}

}

private IList<SPWorkflow> _internalList;

Note: Please note that periodically Workflow table is cleared of the completed workflows by a Timer Job.

Step 3: Terminate the Workflow

For terminating the Workflow use the following code.

private void TerminateButton_Click(object sender, EventArgs e)

{

if (List.SelectedIndex >= 0)

{

if (MessageBox.Show("Are you sure to Terminate this Workflow?", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)

{

SPWorkflow workflow = _internalList[List.SelectedIndex];

SPWorkflowManager.CancelWorkflow(workflow);

RefreshList();

MessageBox.Show("Terminated.. The list will be refreshed after Timer Job removes the workflow entry!");

}

}

}

Note: Here we are using SPWorkflowManager class to terminate the workflow. The CancelWorkflow() is the method used to perform the same. After cancelling the item will be removed by a timer job.

Step 4: Execute the Application

On executing the application you can see all the workflows listed. Selecting the appropriate workflow and clicking the Terminate button should make the Workflow Internal State to Cancelled. From this point onwards the obsolete email problem will be stopped.

clip_image018

Note: Currently the workflow author, date and url information are added in the list. You are free to add additional information about the workflow in the list.

References

http://tinyurl.com/sp2010-wf-terminate

Summary

In this article we have explored a possible problem associated with obsolete task emails workflow and the solutions for it.

I would like to iterate that Microsoft recommended way of solution is to use the Server Object Model or Client Object Model to make the database changes rather than using SQL statements directly on the content database.

The source code for the article is attached.

Posted in SharePoint | Tagged: , , , | Leave a Comment »

SharePoint 2010 – Workflows

Posted by JP on August 8, 2012

In this article we can explore the Workflow feature of SharePoint 2010.  It adds much power and flexibility to SharePoint and is a must have skill for advanced SharePoint users or administrators.

What is Workflow?

Workflow started as a component of .Net framework 3.0 named Windows Workflow Foundation.  Workflow represents a sequence of activities as in a Flow Chart and a runtime that executes these activities.  

The Workflow activities get executed inside a:

·         Windows Application

·         SharePoint Server

·         ASP.NET Application

Workflow is integrated in SharePoint 2010.  We can create Workflows using SharePoint Designer, Viso and Visual Studio.

Why we need Workflow?

Workflow provides a convenient way to automate manual business processes.

The activities in the Workflow can be represented in a graphical manner and adds great flexibility to a developer and non-developer.  Using Workflow we can easily achieve the branching, cases and executions in an easier manner.

Inside SharePoint, the Workflow feature enables an easier way of associating activities Approvals, Rejections, Copying, Moving, Email Notifications with Document Libraries and Lists.

Scenario to reveal the advantage of Workflow:

Create a Task List of Id, Name, and Status.

When Status is Completed,

Move the item to Completed Task List

Time Required

Using ASP.NET

8 Hours

Using SharePoint and Workflow

5 Minutes

 

From the above scenario We can understand the cost and time savage using Workflows.  It allows dragging and dropping the common programming scenarios.  We can also do advanced activities by programming extension of Workflows.

Common Workflow Scenario

We can apply Workflow for the following scenarios.

Scenario 1: A task list allows creation of task for users.  Whenever a new task is created in the list, we need to notify the user associated with it.   We can use Workflow to accomplish this easily.

Scenario 2: A company consists of developers with various skill sets.  There is a set of Training Items.  Each developer can apply for the training.  The application will be notified to the Training Manager.  He can check the skill set and approve or reject the applicant.  If selected, the applicant can attend the training.  On completion of training there is a verification exam to be undergone by the attendee.  If he passes then Certificate is issued else the notification through email is done. We can use Workflow to accomplish this easily.

Scenario 3: People upload their expense reports into a Document Library.  The library captures the expense as a separate field.  Every week manager has to change status to Approved for the expenses with less than $ 500.  The list contains hundreds of entries.  The status updation can be done using Workflow in just 1 minute.

Scenario 4: Client can create a bug and it should be notified to Developer through email.  Developer on completion of the bug fix changes the status and the Client gets notified.  This whole process can be done through Workflow in an easier manner.

The above scenarios shows that a good amount of programming effort is needed to provide a solution.  Using Workflow with SharePoint we can reduce the effort considerably.

When the activities are getting complicated in the business world, Workflow provides a graphical and modular approach in addressing them simply.

Reusable and Non-Reusable Workflows

In the case of SharePoint 2007 the workflow created for one list cannot be used for another list.  But in SharePoint 2010 the same workflow can be applied for multiple lists and thus making it Reusable.  We can create reusable workflows using SharePoint Designer 2010. 

There is a similar term called Globally Reusable Workflow which requires conversion of existing Reusable Workflow.  Once it is converted the Workflow can be used with the whole site collection.

We can export the workflow as a template to be used with another site collection.  We can also import the WSP (Windows SharePoint Solution) file inside Visual Studio using the Import Reusable Workflow wizard.

Manual and Automatic Invocation of Workflow

We need to mention that there are 2 ways of starting a Workflow:

·         Manual

·         Automatic

In the case of manual start, the user / administrator has to click some buttons for the workflow to start.

In the case of automatic start the workflow executes automatically.  This can be configured along with a list/library like:

·         Start on Creation of Item

·         Start on Updation of Item

etc.

Typical Workflow Usage in SharePoint

·         Developer creates the Workflow

·         Administrator deploys the Workflow

·         Site Users use the Workflow

Designer, Visio and Visual Studio

The SharePoint Designer provides an easier way for Administrators and Developers to create Workflows.  Along with Microsoft Visio, Designer provides much more flexibility and features in Workflow creation.

Using Visual Studio developers can write more complex programming tasks with Workflow.  Using the SharePoint extensions for Visual Studio, the inbuilt templates provides easier Workflow creation and deployment.

References

http://msdn.microsoft.com/En-US/library/aa480215.aspx

http://sergeluca.wordpress.com/2011/01/06/step-by-step-tutorial-creating-workflows-for-sharepoint-2010-step-115/

http://www.codeproject.com/Articles/70867/Reusable-and-Globally-Reusable-Workflows-in-ShareP

Summary

In this article we have explored the Workflow feature of SharePoint 2010.  In the next article we can experiment with creating workflows.

 

Posted in SharePoint | Tagged: , | Leave a Comment »