Blog

You are browsing the archive for Workflow.

Video: How to Create a Custom Task Notification with a SharePoint Designer 2010 Workflow

May 25, 2012

Two years ago I wrote a blog post about How to Create a Detailed Custom Task Notification with a SharePoint Designer Workflow. That blog post provided step-by-step instructions and screenshots for doing this in SharePoint 2007. I received a lot of questions asking for more information explaining the steps. Back in December I finally decided to record a video of showing how to do this same thing in SharePoint 2010. However, I got tied up with other work and just now realized that I had never posted that video here on the blog. Oh well, better late than never, I guess.

I think you’ll find that I explain things in much more detail in this video and you get to see all the steps that are involved as well. As always, if you have questions, let me know in the comments and I’ll do my best to answer them as time allows.

Click here to watch the video on YouTube.

What Replaced the Build Dynamic String Workflow Activity in SharePoint Designer 2010?

July 29, 2011

Build Dynamic String Action in SharePoint Designer 2007One of the SharePoint Designer workflow activities I use most in SharePoint 2007 is Build Dynamic String. It is a very convenient way to create a customized string of dynamic text that I can then use and re-use for email subject lines, descriptions, task titles, and all sorts of things.

Unfortunately, Microsoft made the decision to disable the Build Dynamic String workflow activity in SharePoint 2010. You may have already discovered Greg Osimowicz’s blog post about how to re-enable the Build Dynamic String activity in SharePoint 2010. However, not only is this method neither recommended or supported by Microsoft, but if you aren’t the SharePoint Server administrator, you probably can’t edit the WSS.Actions file anyway. So, how can YOU, as a workflow designer, Build a Dynamic String in a workflow in SharePoint Designer 2010?

Utility Actions in SharePoint Designer 2010In SharePoint 2010, Microsoft has replaced the Build Dynamic String activity with four new Utility Actions to Extract Substrings. While all of them are useful, only one of them properly replicates the Build Dynamic String activity from SharePoint 2007: Extract Substring from Index of String. In this post I’ll explain how to use this and then explain why the other three don’t properly duplicate the Build Dynamic String function.

How to Use Extract Substring from Index of String Workflow Activity

When you add the Extract Substring from Index of String activity to your workflow, it will look like this:
Extract Substring from Index of String

You’ll notice that there are three parameters you can edit: the original string, the starting character, and a variable to store the result. If you change the starting character from 0 to 1, this activity will work exactly like the Build Dynamic String activity did in SharePoint Designer 2007. Here, you can see how the parameters line up:
Comparing Build Dynamic String to Extract Substring from Index of String

When you click on string, you will have the option of clicking on an ellipses button […] to Display builder for this parameter, or the [fx] button to Define workflow lookup. If you click on the ellipses, you will see the String Builder window just like you were used to in SharePoint 2007. Use this window to build your dynamic string as you want it. Then change the Output Variable to a variable of your choosing. That’s all there is to it! This
Click on the Ellipses to launch the string builder

Something to Be Aware of – In order for this to work, you must change the starting at value to 1. If you leave it at 0, you will end up with an empty string. If you use a value greater than 1 your final string will be missing characters at the beginning.

Why the Other Three Extract Substring Activities Won’t Replicate Build Dynamic String

The other three Utility Actions are: Extract Substring from End of String, Extract Substring from Start of String, and Extract Substring of String from Index with Length. You can see these three activities and their parameters in the screenshot here (in the order I listed them):
Utility Activities for: Extract Substring from End of String, Extract Substring from Start of String, and Extract Substring of String from Index with Length

You’ll notice that each one has a variable for the number of characters. If you leave this at 0, your variable will contain an empty string. Also, if you enter a number that is greater than the length of your string, it will contain an empty string! So, these activities are only useful if you know the exact length your output string needs to be; this is very unlikely if you are building a dynamic string (it is dynamic, remember). These actions will only return a value if the number of characters parameter is less than or equal to the length of the string parameter.

So, there you have it. I hope you find this useful.

How to Add and Subtract Hours and Minutes from Date and Time Fields in SharePoint Lists

April 26, 2011

I recently needed to write a SharePoint Designer workflow to send a reminder email 12-hours before the end of a multiple-day event. It’s easy to use the Pause Until Date activity to pause until the necessary time, but it’s not so obvious how to calculate the date and time ithe workflow needs to pause until.

The easiest way to calculate the Pause Until date and time was to create it as a calculated column in SharePoint. Note: although the screenshots in this post are from SharePoint 2010, the principles are the same in SharePoint 2007.

In the Name and Type section, for the name of the column name I used DateTime for PauseUntil. I selected the Calculated (calculation based on other columns) data type.
image

In the Additional Column Settings section, I temporarily entered a formula of =[End Time]-1, selected Date and Time as the data type, and selected Date & Time as the format.
image

You’ll notice in the screenshot here that there are three different End Times and the calculated column subtracts exactly 24 hours for the =[End Time] –1 formula.
image

If we divide 1 day by 24 hours and divide 24 hours by 60 minutes, we get 1/24/60 = 0.00069444444. So, if you change the formula to =[End Time]-1/24/60
image
you’ll notice that the dates and times in the Date for PauseUntil column are exactly one minute before the dates and times in the End Time column.
image

What this means, is that to add or subtract a certain number of minutes from a date and time field, we just need to multiply 1/24/60 by the number of minutes we want to add or subtract. In my problem, I needed to subtract 12 hours which is 12*60 or 720 minutes. Let’s see if that works…
image

Yep, all the calculated times are exactly twelve hours before the end time; and if you’re wondering, crossing midnight times doesn’t cause any problems for these calculations.
image

So, if you need to add or subtract a certain number of hours or minutes in a calculated column in SharePoint, you can simply multiply 1/24/60 by the number of minutes you need to add or subtract to achieve any value you need.

Special thanks goes to Mike Smith for his response in this discussion board thread for originally sharing this tip. I wrote this post in an attempt to break it down a little bit more and add screenshots in hopes that some others might find the information a little more understandable.

Create a Detailed Custom Task Notification with a SharePoint Designer Workflow

March 24, 2010

Update June 6, 2012: If you would like to know how to do this in SharePoint 2010, click here for a video tutorial.

It seems that few SharePoint users are happy with the out-of-the box task notifications. While they serve their purpose, we often want highly customized emails that contain more information about the task.

I recently created a workflow that used the Collect Data from a User activity. When you go through the Custom Task Wizard, SharePoint Designer creates a Content Type (based on the parameters you selected) in your site and adds that content type to the Workflow Tasks list for the site. The task notifications use the standard template though and look like this:
image

So, in this example, Alan needs to correct something in inventory. He can see that an item called “Shipped to Dan’s Bikes” created the task, but he really doesn’t have any idea what he needs to correct, or why he needs to correct it. He could probably figure it out if he clicked on the link to Shipped to Dan’s Bikes, but that’s not very intuitive and still means more work for Alan. If he clicks on the link to Edit this task, he doesn’t get much more details there:
image

Alan would like to receive an email with all the details he needs and a link to this form to enter his count.

We’ll need to do a few things to replace SharePoint’s default notification with our own. The first thing we need to do is turn off SharePoint’s default notification. On the Workflow Tasks list, go the Advanced Settings and select No for Send e-mail when ownership is assigned.
image

Next, you’ll need to launch SharePoint Designer, open the site, and create a new workflow.Attach the workflow to your Tasks list and select the option to run when a new item is created.

It’s possible that your Tasks list could contain multiple types of content types, so you’ll want to add conditions in your workflow for each Content Type or create separate workflows for each Content Type. My Content Type was called Inventory Correction, so I check for that in my first condition:
image

I want my email notification to contain some details about the task and be less generic than the out of the box notifications. You’ll remember that notification just said, “Tasks – Inventory Correction Has Been Assigned To You.” I would like it to say, “New Task: Correct Inventory for the Appalachian Mountain Bike” so that the recipient had a better idea of what he had to do. So, the first action I added to my workflow was Build a Dynamic String. In the String Builder, I typed in the my static text and added a Lookup to get the name of the bicycle from the list item on which the workflow was running that created the task. To find this I matched the Current Item: Workflow Item ID with the ID of the item in the Inventory Adjustments list (that is the list that triggered this task to be created). The lookup looked like this:
image

And the Dynamic String looked like this:
image
I stored that string in a variable named New Task Title. 

So, another important lesson here is that the Workflow Item ID always matches the ID of the item on which the workflow was running that created the task, so it can be used to get to any of that information. Sweet!

Next, I added an action to my workflow to Send and Email. In the Define E-mail Message dialog, I set the subject line to be the Dynamic String I just created.

I also wanted a link directly to the form to edit the task. So, I opened up an existing task and copied the URL for it from my address bar. I added some HTML anchor tags to my email and pasted this URL in as the HREF. I also needed to Look Up to change the ID for the task.

In the body of the email, I used the Workflow Item ID to do lookups on the Inventory Adjustments list to dynamically populate the Bicycle Type, who created the adjustment that caused the problem, and the original adjustment amount. Here is what my completed dialog looked like.

image

Finally, I wanted to change the Title of the task in the task list to provide more information. I used the Set Field in Current Item activity to change the Title to be the same thing as the subject line of the email. Here is what the complete workflow looked like:
image

When this workflow runs, it changes the Title of the task from the default “Inventory Correction” (which is the name of the Content Type) to “New Task: Correct Inventory for the Appalachian Mountain Bike.”image

And the Warehouse Manager gets an email with a link to the edit task page and all the details about why he needs to make the correction:image

If you want to learn more about how to take you SharePoint Designer workflows to the next level, be sure to sign up for our Mission: Automation – SharePoint Workflow and InfoPath class! Hopefully I’ll see you there!

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

Use SharePoint Lists to Create a Filtered Drop Down in InfoPath 2007

January 27, 2010

While teaching our online class on InfoPath and SharePoint Designer Workflows (Essentials of InfoPath and SharePoint Workflows), I was asked about using SharePoint list data to populate InfoPath drop-down list controls and filtering a list control based on the selection of another drop-down.

Goal: To create an InfoPath form that includes two drop down lists populated from an external source (SharePoint lists) with the result of the first list selection filtering the second.

Scenario: Adventure Works has four types of bikes that they manufacturer:

· BMX
· Mountain
· Racing
· Touring

They have many bike models for each type of bike (Mountain bikes for example are comprised of the following: MX-100, MX-200, MX-220, MX-300, etc.)

Customer service has a form to track issues from customers. They need to select the model from a list but would like to be able to filter the list of bike models based on the type of bike.

Overview of the steps

In SharePoint:

Create a custom list to maintain the bike types
Create a custom list to maintain the current bike models (with a lookup to the Bike Types list)

In InfoPath:

Create a form
Add a drop down list control and connect it to the bike types list
Add a list (or drop down list) control and connect it to the Bike Models list
Set a filter to filter the models based on the selection from the first control

Detailed directions

1. At the top-level site in the site collection (portal.awbikes.local in the classroom environment) create a custom list named BikeTypes

2. Change the ‘Title’ column name to ‘BikeType’

3. Add the following four items to the list: BMX, Mountain, Racing, Touring

clip_image002

4. Create another custom list named ‘BikeModels’

5. Rename the ‘Title’ column ‘ModelNumber’

6. Add a lookup column named BikeType and lookup to the Biketypes list, BikeType column

7. Populate the list with a number of model numbers and choose a type for each
clip_image004

8. In InfoPath, design a new form using a blank template

9. In the Layout task pane add a Table with Title then add a two-column table in the body

10. Resize the rows and columns and hit the tab key a few times to create more rows in the two-column table as follows:
clip_image006

This list will contain many fields including date, customer contact info, issue type, issue description, etc. We are only going to work with the bike type and model fields here.

11. Switch to the Data Source task pane and rename the ‘myFields’ group to CustomerService

12. Under Actions, click Add a Field or Group and add a Text type Field named BikeType
clip_image008

13. Add another text field named BikeModel
clip_image010

14. Drag the two fields into the form
clip_image012

15. Right-click the BikeType control and change to a Drop-Down List Box
clip_image014

16. Right-click the BikeModel control and change to a List Box

17. Double-click the BikeType control and under the section titled List box entries, select the radio button for ‘Look up values from an external data source’ and click Add
clip_image016

18. Select Create a new connection to: and Receive data, Next

19. Select SharePoint library or list, Next

20. Enter the URL of your site where you created the custom lists above (in class, http://portal.awbikes.local), Next

21. Choose the BikeTypes list, Next

22. Select the BikeType field, Next

23. Select ‘Store a copy of the data…’, Next

24. Enter a name for the connection, BikeTypes, select the ‘Automatically retrieve data…’, Finish

25. Click the XPath button for Entries
clip_image018

26. Expand the folders and select BikeType, OK, OK again to finish
clip_image020

27. Preview the form to test the connection to the Bike Types list
clip_image022

28. Close the preview and double-click the BikeModel list control and under the section titled List box entries, select the radio button for ‘Look up values from an external data source’ and click Add

29. Select Create a new connection to: and Receive data, Next

30. Select SharePoint library or list, Next

31. Enter the URL of your site where you created the custom lists above (in class, http://portal.awbikes.local), Next

32. Choose the BikeModels list, Next

33. Select both the ModelNumber and BikeType fields, Next
(you will just display the ModelNumber but you will use the type in the filter below)

clip_image024

34. Select ‘Store a copy of the data…’, Next

35. Enter a name for the connection, BikeModels, select the ‘Automatically retrieve data…’, Finish

36. Click the XPath button for Entries

37. Expand the folders and select ModelNumber, click Filter Data
clip_image026

38. Click Add

39. Set the filter to BikeType, is equal to, Select a field or group…

clip_image028

40. On the Data Source drop-down, select Main, Bike Type, OK, OK, OK, OK, OK already!
clip_image030

41. Preview the form to test the filtering
clip_image032

You can create the filtering using only one list (just BikeModels) by selecting the Show only entries with unique names option. For very large lists this may impact performance.

Happy filtering!