SharePoint

Looping through SharePoint List Items In A Workflow

April 21st, 2010  |  Published in SharePoint

Sometimes you need to have a workflow that loops through all the items in a list and then matches them on some criteria and performs an action.  Considering the following all-to-often occurring scenario…

You setup a list of tasks, or some sort of tracking list and assigned tasks go uncompleted because people don’t mark them as complete.  This will happen to you if you use SharePoint.  Death, taxes and incomplete SharePoint tasks are 3 things that are unavoidable in life.

You need a way to remind them that they have an open task assigned to them.

The problem is that SharePoint does not support a workflow that runs against the entire list.  Workflows run against a single item.  Whichever item initiated them.

The key to solving this without cracking open Visual Studio is to resign yourself to working with a single object at a time.  Instead of a workflow that runs AGAINST all list objects, we are going to create a workflow (2 actually) that runs FOR each list object. 

The idea here is recursion.  Recursion is a programming principle that simply means a function or method that calls itself.  Simple.  What we need is a workflow that calls itself.  The workflow should just run non-stop until a condition is satisfied and then an action is taken.

This is not possible anymore as of SP 2 – which is a good thing because you don’t always want endless looping in your workflow.  As of SP 2, a workflow can no longer initiate itself.

We can get the same effect using 2 workflows.  Here is the logic..

  1. We have a field in our list item that the user never sees called “BeingProcessed”.  It’s a Yes/No field that defaults to “No”.
  2. We have 1 workflow that initiates manually, on create and on change.
  3. We have a second workflow that initiates only on change

Here is the kicker – both workflows are going to do EXACTLY the same thing.  Here is the workflow logic in psuedo code…

if the BeingProcessed field of the current item is “No” and our other condition is satisified (for instance, the modified date is 2 days old and the task is still open), we are going to set the BeingProcessed flag to Yes, send an email to the assignee asking them to please close the task, and then we are going to set the BeingProcessed back to No.

else if the BeingProcess field is “No” and our other condition is not satisified, we are simply going to set the BeingProcessed field to “Yes” and then sleep for a certain amount of time (lets say 24 hours).  After that, we are going to set the BeingProcessed back to “No”.

What does this do?

It causes 1 workflow to either take an action or sleep for 24 hours and then wakeup and change the item which causes the SECOND workflow to kick off and do exactly the same thing, initiating the first workflow after it completes by also updating the item.  What we then get is a single workflow that is running ALL the time on a given item until certain conditions are met.  It seems heavy handed, but all we are doing is a quick check and then going to sleep for 24 hours.  It’s very light when you think about it.

That’s an easy way to do “looping” without writing a single line of custom code.  ALL of that can be done in SharePoint Designer.

Top 5 Free SharePoint Tools

March 30th, 2009  |  Published in SharePoint

I really struggled over how to name this post.  I wanted to say it was the Top 5 Free SharePoint Web Parts, but it’s so much more that that.  These are the top 5 free SharePoint Tools according to me.  It is a selection of what I think are the best free tools for SharePoint that came from the community.  Keep in mind that these are my personal top 5, not by any means a comprehensive or definitive list.

5.  CKS World Clock And Weather

The CKS World Clock And Weather web part is a contribution to the larger Community Kit For SharePoint by Bamboo Solutions.  It displays the time from around the world as well as weather by city.  It has a great toolpart which automatically finds cities based on what you type.  In any kind of intranet environment, you will no doubt be asked to provide the weather as one of the first things.  Business users assume this is easy to do since it’s so readily available on every sort of customizable internet page out there.

In 2003 we had the MSNBC web parts but those are absent in 2007.  If it weren’t for the CKS web part, we would have a tough time explaining why we couldn’t display the weather in SharePoint out-of-the-box.

4.  ChartPart

SharePoint provides some fairly robust dashboarding with Excel Services – but what if you don’t have an enterprise license?  ChartPart wraps the very flexible and powerful Charting Controls For .NET 3.5 into a web part which will chart your list data.  You can choose from several different types of charts and there is a ton of great ability in customizing the chart.  Because it charts SharePoint internal data, in the end it really gives you charting ability that you would not have so easily – even with Excel Services and SP Designer.

3.  SmartPart

Is it ironic that I name Smart Part as my number 3 best SharePoint tool after my previous post on why I don’t use it?  Don’t misunderstand – I don’t use it, but I still love it.  Furthermore, different deployments call for different methodologies.  Some choose to build their entire portal with SmartParts.  I also believe that SmartPart STILL saves SharePoint for a lot of companies since SharePoint development is, for the most part, still not very well documented and or a widely found skill.  It bridges the gap to ASP.NET developers which is a big deal for a lot of tech managers who want SharePoint and are under the impression that any ASP.NET developer should immediately be able to begin developing without any additional training.

2.  SharePoint SUSHI

Up until now we have reviewed only web parts.  Now we take a step to the administrative site with SUSHI.  It’s an acronymn that stands for SharePoint Utility with a Smart, Helpful Interface.  It simplifies a multitude of administrative tasks, including bulk document uploading, profile image uploading, themeing and bulk site creation.  This tool is so important to me with just the bulk document and profile image upload functions.  There are plenty of pay-for tools that you can get to do these same things plus much more, but this is the most robust free tool I have found so far.

1.  STSDEV

It’s no contest to me that this one is number 1.  This is a tool which generates a Visual Studio project solution which GREATLY simplifies developing features for SharePoint.  I love this tool because it is so easy to use and so well documented.  No – there is no canvas still, but it does package everything up for you so nice a neat and lets you not worry about all of the things it takes to make a portable and deployable SharePoint feature.

These are my top 5 favorite free SharePoint tools.  One of the things I enjoy the most about SharePoint is the community which takes the time to provide each other with the support and tools it takes to be successful.