Blog

You are browsing the archive for Workflow.

Use Multiple Selection Columns in Calculated Fields

February 22, 2010

I recently had a need to create a hyperlink in a custom list and the hyperlink needed to contain parameters that came from a Choice type column that allowed multiple selections. I’m very comfortable using Excel’s string functions (LEFT, RIGHT, MID, LEN, and FIND) to parse strings and I’ve done so many times. However, when I tried to write a formula using the Multiple Selection field, I got an error that said, “One or more column references are not allowed, because the columns are defined as a data type that is not supported in formulas.” Rats! I thought that we might need to write an event receiver with Visual Studio to accomplish my task, but I really wanted to find a way to do it without writing any code. Here is what I did to solve the problem.

The Problem

In this particular scenario, a department stores information about events in a custom list. There may be one or two people from the department who attend the event. The names of these employees are stored in a column of type Choice that has been set to display as Checkboxes (allow multiple selections).

They use a web based program as part of managing the event. Information about the event is passed to web application as variables in the URL. Two of those parameters are the employees who are attending the event. They want SharePoint to automatically create the URL and modify it if the item changes.

Here is a simplified example of what they want to see in their SharePoint list:
image

The Solution

This customer is using our Workflow Essentials product that adds 24 more activities to SharePoint Designer workflows. I decided to make use of two of the Text Capture activity to extract the parts of the string I needed (if you are interested, you can watch a short video on how the Text Capture, Text Replace, and Text Validate actions work).

The Text actions in Workflow Essentials use Regular Expressions to look for values within text (a great place to learn more about Regular Expressions is: http://www.regular-expressions.info/).

When a column is set to allow multiple items to be selected, SharePoint stores them in a plain text format with the items separated by semicolons; you can see this in the example above.

The first Regular Expression I wrote extracted the first word in the My Persons string. The That regular expression is: ^\b[A-Za-z]+\b
The second Regular Expression I wrote extracted the second word in the My Persons string. That regular expression is: \b[A-Za-z]+\b$

Note that regular expressions don’t actually extract anything, but rather returns the part of the original string that matches the given regular expression. These two expressions worked in my case because my strings consisted of single words that consisted only of singe letters and there was a maximum of two words total. If my string had different qualities, I would have to have written totally different regular expressions to match my particular criteria. Writing Regular Expressions is a very valuable, and often under valued, job skill. I’m not an expert at it so I won’t likely be a good source for writing a regular expression for your particular case. Sorry.

Once I had written my Regular Expressions, I was ready to create my solution. I launched SharePoint Designer and created a new workflow on my list that would run when a new item was added or when an item changed.

I added the Text Capture activity first, used my first Regular Expression as pattern and output the captured text to a variable named FirstChoice. Then I added another Text Capture activity where I used my second Regular Expression and captured the matched text to a variable named SecondChoice. Next I added a Build Dynamic String activity where I composed the URL and inserted the two variables in the appropriate place for the URL parameters. Finally, I added a Set Field in Current Item activity where I set the My URL field to the string I had just created. Here is the entire workflow.
image

As you can tell, Workflow Essentials is a powerful product that can greatly increase the power of your SharePoint Designer workflows. Check it out!

InfoPath Form with Multiple, Dynamic Approvers

February 19, 2010

A question came in to the MOSS Help and How To forum about creating a form that allowed multiple approvers to be specified at the time the form is being filled out.

I went ahead and created a form in InfoPath and a simple workflow in SharePoint Designer to allow the selection of the approvers and assign tasks for the approvers. It is a simple form and workflow both. For production you would want a more robust solution. If you have ideas for a better solution, please let me know in the comments.

Instead of writing out all of the steps I created this short video to demonstrate how the form, workflow, and SharePoint library work.

MOSSHelpPlay

Creating SharePoint 2010 Workflows in Visio 2010

October 18, 2009

Microsoft is taking a bit of the chore of designing workflows off of designers and letting business users define their own workflow layouts in Visio 2010 before exporting to SharePoint Designer to associate it with a List or Site. This allows business users to use a familiar graphical tool to define the steps in the workflow themselves instead of having to communicate their needs to designers or developers through a requirements document. The resulting Visio workflow can be used as the actual initial building block in the workflow.

 

Visio includes a brand new template aptly called Microsoft SharePoint Workflow that includes Condition and Activity shapes specific to SharePoint workflows.

 

 

Visio Conditions, Activities and Terminators

 

 

Not all of the Conditions and Activities currently match up to those available in SharePoint Designer.

 

This information is currently based on Technical Previews of both Visio 2010 and SharePoint Designer 2010 and both are subject to change in the Beta version due out later this year. It is also important to note that Designer connects directly to the SharePoint site and retrieves a list of available conditions and activities currently installed on the site including any created in Visual Studio and any 3rd party installed solutions, whereas Visio does not; the list available in Visio is static in this preview version. The ability to connect to the target site in Visio would be a great addition and would help to allow business users to build a more complete workflow ready for installation into a SharePoint site.

 

Creating a workflow will come naturally to users familiar with creating charts in Visio using drag and drop from the Shapes tabs and connecting them on the workspace, with the only difference being the SharePoint specific shapes. Below is an example of a simple workflow created in Visio 2010.

 

 

Visio currently does not include any Shape Data on any of the shapes, meaning that although you can drop a “Send an Email” activity onto the workspace, you cannot specify any of the properties on the activity such as the To address, Subject or email Body. A designer will need to import the workflow into SharePoint Designer for final configuration and publishing to a list or site. I will show shortly how Visio stores attributes for the shapes when exporting the workflow. The addition of the shape data would be the final piece that would allow business users to build a complete workflow ready for publishing and I am hopeful that this will be included in the beta and/or final release of Vision 2010.

 

After completing the workflow, it is necessary to check it for errors in logic. Visio 2010 includes the “Check Diagram” option from the Process tab of the Ribbon.

 

 

By default, the Check Diagram feature includes the “SharePoint Workflow” option as the rule base to check the workflow against. Clicking on “Check Diagram” will result in Visio checking the logic against SharePoint’s rules and will either notify that no errors where found or give a list of errors in the Issues Window below the workspace. Clicking on an issue will highlight the offending object making it easier to determine the cause and fix the problem.

 

Example of an error in the Issues window.

 

 

After successfully checking the workflow, you now must export it to the file system so that it can be imported into SharePoint Designer. On the Process tab of the Ribbon are the Import and Export buttons. Import allows you to open workflows created in SharePoint Designer for graphic representation and documentation. Since it is possible to create a workflow in Designer that uses activities built in Visual Studio that Visio does not know about, those activities show up as a generic Activity with the name “Custom Action”.

 

Exporting is as easy as clicking the Export button and choosing a filename and location. Visio 2010 will save the workflow with a .vwi extension. By simply renaming this file with a .zip extension you can open it and reveal the following 4 embedded files.

 

[Content_Types].xml

This file simply stores a list of the extensions of the files embedded in the .vwi file.

 

workflow.vdx

This is the Visio definition file for the workflow including file properties and layout details for the workspace. When building a workflow in Designer, you will notice each condition or activity includes a sentence where you set properties for its parameters. This file contains the text for those sentences for use when importing the workflow into Designer.

 

workflow.xoml

Designers and developers familiar with creating workflows in SharePoint Designer will be familiar with this file. It is an XML representation of the workflow including all conditions and activities and their parameters. Although Visio does not include shape data on the workspace, when exporting the workflow, the appropriate parameters will be included in this file. When importing the workflow into Designer, it uses this file to get the logic for the workflow as well as all of the parameters and values for each condition and activity. The exported file will have the value {x:Null} set for each parameter since there is no way to set these in Visio.

 

Here is a sample .xoml file as created when exporting the workflow shown above. The SequenceActivity section has been highlighted to show how the workflow logic including the conditions and activites is written to this file.

 

<ns0:RootWorkflowActivityWithData x:Class=”Microsoft.SharePoint.Workflow.ROOT” x:Name=”ROOT” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/workflow” xmlns:ns1=”clr-namespace:Microsoft.SharePoint.WorkflowActions.WithKey;Assembly=Microsoft.SharePoint.WorkflowActions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=null” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:ns0=”clr-namespace:Microsoft.SharePoint.WorkflowActions;Assembly=Microsoft.SharePoint.WorkflowActions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=null”>

    <ns0:RootWorkflowActivityWithData.WorkflowFields>

        <ns0:WorkflowDataField Name=”__list” Type=”System.String” />

        <ns0:WorkflowDataField Name=”__item” Type=”Microsoft.SharePoint.Workflow.SPItemKey” />

        <ns0:WorkflowDataField Name=”__context” Type=”Microsoft.SharePoint.WorkflowActions.WorkflowContext” />

        <ns0:WorkflowDataField Name=”__initParams” Type=”Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties” />

        <ns0:WorkflowDataField Name=”__workflowId” Type=”System.Guid” />

        <ns0:WorkflowDataField Name=”calc” Type=”System.Double” />

    </ns0:RootWorkflowActivityWithData.WorkflowFields>

    <ns0:OnWorkflowActivated x:Name=”ID1″ WorkflowProperties=”{ActivityBind ROOT,Path=__initParams}”>

        <ns0:OnWorkflowActivated.CorrelationToken>

            <wf0:CorrelationToken OwnerActivityName=”ROOT” Name=”refObject” xmlns:wf0=”http://schemas.microsoft.com/winfx/2006/xaml/workflow” />

        </ns0:OnWorkflowActivated.CorrelationToken>

    </ns0:OnWorkflowActivated>

    <ns0:ApplyActivation x:Name=”ID2″ __Context=”{ActivityBind ROOT,Path=__context}” __WorkflowProperties=”{ActivityBind ROOT,Path=__initParams}” />

    <SequenceActivity x:Name=”ID3″>

        <IfElseActivity x:Name=”ID4″>

            <IfElseBranchActivity x:Name=”ID5″ Description=”ShapeGuid={5C21D244-2AB1-4447-A2BA-CE6431839784};PageId=0;ShapeId=4;”>

                <IfElseBranchActivity.Condition>

                    <RuleConditionReference ConditionName=”__Rule_ID5″ />

                </IfElseBranchActivity.Condition>

                <ns0:EmailActivity x:Name=”ID6″ __Context=”{ActivityBind ROOT,Path=__context}” To=”{x:Null}” Subject=”{x:Null}” Description=”ShapeGuid={268E5AD8-F73D-4519-A56D-62246EAA3B33};PageId=0;ShapeId=8;” BCC=”{x:Null}” CC=”{x:Null}” Body=”{x:Null}” />

            </IfElseBranchActivity>

            <IfElseBranchActivity x:Name=”ID7″>

                <ns1:SetFieldActivity x:Name=”ID8″ __Context=”{ActivityBind ROOT,Path=__context}” Description=”ShapeGuid={560EFD0C-3C56-41B6-BA1C-723C4ADE3FDD};PageId=0;ShapeId=12;” FieldName=”{x:Null}” __ListItem=”{ActivityBind ROOT,Path=__item}” __ListId=”{ActivityBind ROOT,Path=__list}” />

            </IfElseBranchActivity>

        </IfElseActivity>

    </SequenceActivity>

</ns0:RootWorkflowActivityWithData>

 

workflow.xoml.rules

This file defines the rules used when checking the workflow for errors.

 

SharePoint Designer leaves behind the old look and feel of Front Pages; in 2010, it fits right in with the Office suite. In this technical preview, there are a few pieces that are not as obvious to access and even completely hidden and this is bound to get under the skin of technical designers and developers. However, my thoughts are that most of them may likely make their way into the public release due out by the time of this writing. I will only discuss those features associated with workflows in this article.

 

To see the list of workflows for the loaded site, simply click Workflows on the left Navigation bar.

 

 

 

Importing a workflow from Visio 2010 is as easy as going to Workflows on the left Navigation bar and then clicking the “Import from Visio” link in the new Ribbon at the top of the window. You are prompted to locate the .vwi file created by Visio 2010 and to name and associate the new workflow with a list on the site, or to make it a Reusable workflow.

 

After importing the previous workflow shown in Visio, you come to the Edit screen for the workflow where you can define the values for the parameters as well as add additional conditions and activities.

 

 

 

The Ribbon is context specific and now contains buttons for building and publishing the workflow. The Manage section includes buttons for Checking for Errors, Publishing the workflow and exporting as a .vwi file to Visio.

 

The Modify section includes buttons for moving activities around in the workflow as well as an “Advanced Properties” button where you can set the parameters for the selected condition or activity. This allows you to set values for the parameters directly as opposed to using the standard DesignerType. Clicking on the parameter in the sentence allows you to set the values using the Designer Type pop up window.

 

Example of using the Advanced Properties button from the Ribbon to set parameter values

 

Example of using the DesignerType pop up window to set parameter values

 

The Insert section includes buttons for editing the logic of the workflow; inserting steps, conditions and actions, running sections in parallel and adding steps that use Impersonation to run as the workflow author.

 

Lastly, the Variables section includes a Forms Parameters button to define parameters used to gather data from the user on the Initiation and Association forms when the workflow runs. It includes the Local Variables button for creating variables for use within the workflow and that can be accessed as lookups on the workflow. The Variables section also includes an Association Columns button which allow you to automatically create columns on a list when the workflow is associated with it. The purpose of this is to make sure that these columns exist if the workflow depends on them for setting or gathering data.

 

The next logical step is to configure the parameter values in the workflow. As stated before, Visio 2010 does not include shape data for the shapes, however it does include all of the proper parameters in the .xoml file when exporting the workflow so the show up properly when importing into Designer. This is done by either using the Advanced Properties button or clicking on each parameter and using the pop up windows as described earlier.

 

Clicking on the Publish button validates the workflow for errors, saves the .xoml file and makes the association with the list in the content database. One of the options missing that developers in particular may miss, is the fact that there is currently no way to view the .xoml in Designer as there was in 2007. You will have to Export to Visio to produce the .vwi file to get access to the xoml code. If you make any changes to it, you will need to import the .vwi back into Designer.

 

When Publishing the workflow I have come across some errors in validation associated with the DesignerTypes in 2010. There has been some changes made in the DesignerTypes that will be the topic of another article. Workflows built in Visio 2010 should not be affected, but any existing conditions or activities built in Visual Studio will.

 

The next logical step that does not show up in the Technical Preview of Visio 2010 is the ability to create custom conditions and activities in Visual Studio and import them into Visio as well as the addition of shape data for the shapes in Visio 2010. With this new template addition, business users should enjoy the ability to create their own workflows knowing that what they build will actually become the core of the workflow they will end up using on the SharePoint site.

The New Approval Actions in SharePoint Designer 2010 Workflows

October 18, 2009

SharePoint 2007 came with 23 out-of-the-box actions to fit many of the most common tasks needed in workflows. SharePoint 2010 comes with 44 out-of-the-box actions. All the original actions are still there, but you now have 21 more! Note: This post and all screenshots are from the Technical Preview and things may change before SharePoint 2010 is released to the public.

 

In SharePoint 2007, if you wanted to get approval from a user for something, you usually had to use the Collect Data from a User action, store a reference to the task ID for the task that was created, and then lookup the user’s input later in your workflow as needed. Microsoft has streamlined this process in SharePoint Designer 2010 with the actions for Assign Item for Approval, Assign Item for Feedback, and General Task Process. In this article, we’ll take a look at how these three actions work.

 

The first thing you will notice when you add any of these three actions to your workflow is that in the Editor, they all look identical. In the following screenshot I have added an Assign Item for Approval action to Step 1, and Assign Item for Feedback action to Step 2, and a General Task Process action to Step 3.

 

So, how can you tell them apart? You have to click on the Approval Process link for the action. When you do this, you will see a new page where you can define and customize that overall task process.

 

Let’s work our way around this page to explain what each section does.

 

Task Information

In the Task Information section there are only two options, you can change the name of the Approval Process and the Owner of the task.

Both of these can be changed by clicking on the information you want to change. The Name is a meaningful name to you for this particular process. I recommend changing this to a descriptive name that will help you remember later what this particular process is for and to keep the various approval processes in your workflow distinct. The Owner is the owner or this process; you’ll see where this comes into play when we get to the Settings section.

 

When you change the Name here it also changes the name in the workflow editor.

 

Task Outcomes

The Task Outcomes section, you can define the various outcomes for this particular process. If you selected the Assign Item for Approval action, you will already have the options of Approved and Rejected listed here.

If you want to add other options, you can click the New button to add a new option. In the example here, I have added a Skipped option.

The items you list here will be listed as separate buttons on the task form and will be displayed in the Sequence order you select.

 

Task Form Fields

The Task Form Fields section allows you to collect other information in the task form. For example, if something is approved or rejected, you probably want the person who is doing the approving or rejecting to enter some notes about why the chose to approve or reject it.

 

By clicking the New button, you can add your custom data fields to the form. There is a short wizard that will walk you through the process.


 

If you click the Choose existing field button, you will get a dialog box where you can choose from any of the Site Columns that are already available on your site. This can be incredibly handy since you can define the column one time and then reuse it as needed.

 

Settings

There are only three options in the Settings section.

If you check the box for Only allow task recipients and process owners to read and edit workflow tasks then those are the only people who can do those activities. Do you remember when you could set the process owner in the Task Information box? Well, this is where that process owner is used.

 

There are also boxes to allow users to reassign the tasks and to change requests.

 

Customization

I’ve saved this section for last because it is probably the most complex of the five configuration sections.

 

Clicking on the Return to Workflow link simply closes the Approval Process editing window and returns you to the workflow Editor.

 

If you click on Change the completion conditions for this task process you will be taken to the Check Exit Conditions section where you can see the underlying conditions that are part of this activity. This is probably where you begin to see how powerful these new Approval Actions really are. Here is a screenshot of the default page without making any changes:

You can add more conditions here if needed, add steps and generally modify the process as you need.

 

If you click on Change the behavior of a single task you will be taken to a place where you can see and change the behaviors for On Task Assigning, On Task Pending, On Task Expired, On Task Deleted, and On Task Completed. Within each of these, you can add your own conditions, actions, and steps. Here is a screenshot of the default page:

 

If you click on Change the behavior of the overall task process you will be taken to a place where you can see and change the behaviors for On Approval Started, On Approval Running, On Approval Canceled, and On Approval Completed. Once again, within each of these, you can add your own conditions, actions, and steps. Here are screenshots of the various sections of the default page:

Whew! That’s a lot of options and configurations that you can do! But were not yet finished! Remember that these were just he settings for the process. If you return to the workflow editor you’ll see that there are still two more options we haven’t looked at yet.

 

Item to Be Approved

You probably expect that the only item on which you can perform the Approval action is the current item. However, if you click on Current Item, you can change that to any list or library item you want.

 

Assigned to Users

Another thing that I found frustrating in SharePoint 2007 was that I couldn’t customize the task and emails that they sent. When you click on the link in SharePoint 2010 to add users, you get a dialog box where you can customize task request, including the title and body that can include lookups. You can even add serial and parallel recipients and have multiple assignment stages.

 

Well, there you have it. You’ve gotten a general overview of the options for the new Approval Actions in SharePoint Designer 2010. If you are overwhelmed, I’m not surprised. In this post, we’ve only just barely scratched the surface of the great things you can do with SharePoint Designer Workflows in SharePoint 2010. You’ll probably need to take a class to learn it all. J