1,804 articles and 14,715 comments as of Monday, March 7th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Wednesday, January 6, 2010

Outing SharePoint Workflows – Linking to Workflows in List Views and Item Displays

Mark RackleyGuest Author: Mark Rackley
The SharePoint Hillbilly

Show of hands, how many people are tired of explaining to users what a SharePoint Workflow is and how to navigate to the workflows???

“Okay, click on the little down arrow, you should get a menu, now click on ‘Workflows’” or “Go to the item display and click on the menu option ‘Workflows’”.

“Now, you see a list of all the workflows… yes… I know the buttons are ugly… yes ma’am/sir, I’ll look into changing that. Okay.. now back to the ugly buttons… no.. ignore that section labeled ‘Running Workflows’. You don’t need to worry about that.. yes ma’am/sir, you can ignore that ‘Completed Workflows’ section.. we are just concerned with the section labeled ‘Start a New Workflow’.  Yes, I agree it’s confusing.  Yes, I know… Yes ma’am/sir I’ll look into that right away…“

How many times have you uttered the words “Sorry, that’s SharePoint”?

I’m sorry, but how un-user friendly is the Workflow interface in SharePoint?  Sure, if you know what you are doing it’s not too bad, but there are a ton of people out there who don’t have a clue what their doing and we get to support them.. yay! job security…

Wouldn’t it make much more sense if there were a link or a button on the display of any item that a user could click for a specific workflow?  Or wouldn’t it be great if on a list view you could execute a specific workflow directly from there?  Wouldn’t that be great? Well… in an effort to make your lives easier I thought I’d post a couple of options for you to take advantage of. I’m wondering if there is an even better way to do this? Maybe someone out there smarter than myself will let me know?

I asked the question on Twitter to find out what people were doing to solve this problem and as always got great advice quickly from Laura Rogers (@WonderLaura), Susan Lennon(@SusanLennon), and Jim Bob Howard (@jbhoward). It seems one method for doing this is to use a Workflow associated with a “Form Action” as described in detail in Natalya Voskresenskaya’s (@natalyvo) blog “Follow Up: Training Classes Scheduling Solution (Full Version)”  (start reading around step 5). I didn’t dig too deep into this solution however because it had you creating the Workflow as a custom Form Action which does not appear to allow you to select existing workflows or use initiation variables.  Custom Form Actions as Workflows looks pretty cool, but not what I’m going for here.

What I want to achieve is placing a link to an existing SPD or Custom Workflow for a list on the display form of an item.  In addition, I’d like to put the same sort of link as a column in a list so you don’t even have to go to the item display if you don’t want to.

Below is the solution I came up with.

By the way, the first thing we are going to do is parse the URL of our desired workflow. Something I’ve discovered while playing around is that if we have an SPD workflow we need to make sure and grab the List GUID and Item ID.  However, if we have a Custom Workflow we need to make sure we have both of those PLUS the Template GUID.  I have not been able to confirm if this is constant and works under all scenarios.  I’m waiting on confirmation from people smarter than myself and if I ever get a definite answer I’ll be sure to update this post.  Again for this blog I will be using a SPD Workflow.  If you have a Custom Workflow you want to also make sure and grab the template GUID.  Other important things to note, if the GUIDs change we need to make sure and update the changes we are doing here to reflect the new GUIDs in your links.  This is a good argument for NOT doing what I’m proposing.  An ideal solution would be able to automatically determine if GUIDs have changed and use those.  I don’t see that being done without custom code though. 

Last side note, I am using the site I created in my blog entry “Creating a SharePoint List Parent/Child Relationship – VIDEO REMIX”.  The only modification is that I created a manual SPD workflow on the Time List to send an email called “Send Email”.  This simple workflow has two initiation variables. “Recipient Email Address” and “Email Message” if you want to follow along exactly.

Okay… enough side notes… let’s get started

Find the URL for your Workflow

First thing thing we need to do is find the URL for the desired workflow that we want to turn into a link/button/whatever.  To do this go by whatever means necessary to the Workflows page for an item (this page:)


Click on the name of the workflow (In this case ‘Send Email’) to get to the Workflow Initiation Page:


No we need to get the URL for this page.  Just copy and paste it from your address bar.  It should look something like:

http://urltosite/Workflows/Send%20Email/Send%20Email.aspx?List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293&ID=3&TemplateID={97dda5cb-6b21-4b11-b1d3-b2081fa01097}&Source=http%3A%2F%2Fmrackleyspdev%2Fblog%2Fissues%2FLists%2FTime%2FAllItems%2Easpx

Let’s break this apart real quick.  There are 5 parts to the url:

  1. Url to Workflow Initiation Page: http://urltosite/Workflows/Send%20Email/Send%20Email.aspx
  2. List GUID: List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293
  3. ID for specific List Entry: ID=3
  4. Template GUID: TemplateID={97dda5cb-6b21-4b11-b1d3-b2081fa01097}
  5. Source URL: Source=http%3A%2F%2Fmrackleyspdev%2Fblog%2Fissues%2FLists%2FTime%2FAllItems%2Easpx

As mentioned earlier, it appears that all you really need to properly execute an SPD workflow are the relative URL for the Page, the List GUID, and the ID for the List Entry.  For Custom Workflows you also need the Template GUID. So the URL we end up needing is something similar to:

/Workflows/Send%20Email/Send%20Email.aspx?List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293&ID=3

Does it hurt to pass the TemplateID and a Source URL as well? Nope, have at it.  However, keep in mind if that TemplateID changes then you will have to keep it in sync.

Put Link to Workflow on Item Display Page

Okay… next thing we need to do is get that URL on a page as a link and pass the correct List Entry ID to it. Best practice for modifying a DispForm is to create a custom page and re-associate the list to that page. Don’t know how to do that?  Luckily, there’s an app.. I mean video for that:



Now that we have our custom display form created we need to place a link on the page from which we will be taken to our Workflow initiation page.  We also need to get the ID for the current list entry and put it into the link.  Luckily, there is already a parameter by default that contains the entry ID called “ListItemId”. 

So, the relative URL we need to put in our link ends up being: “../Workflows/Send%20Email/Send%20Email.aspx?List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293&ID={$ListItemId}”

In the following video I insert an “interactive button” which is basically just a link formatted to look like a button.  You could just as easily manually enter an link in the page directly. 



Inserting a Link to a Workflow in a List View

Okay, now that we have a link to our workflow on the custom display form, lets put the same link into a list view.  This ends up being very similar if not a bit easier. For the following video I am using the child time list from my blog entry “Creating a SharePoint List Parent/Child Relationship – VIDEO REMIX”.  So, if you need help getting the list set up in the first place, go look at those videos. 

The main difference is that the URL for the workflow will change slightly.  We need to use the row ID from the XSLT (which is “@ID”).  Our Link for this part of the site becomes: “../../Workflows/Send%20Email/Send%20Email.aspx?List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293&ID={@ID}”  (note that we had to url encode the “&” to “&” for the second parameter in this scenario. This was done automatically for us before with the dialog for “insert interactive button”).

So, what we are going to do is look through the aspx of our list view and find where it enters the value for the last column (Hours in this example) and then we need to insert a new cell into the list view with the value in the cell being a link to our workflow. This code ends up looking like:

<td class="ms-vb">  <a href="../../Workflows/Send%20Email/Send%20Email.aspx?List=abc587ec-2ce1-4e2f-a2c8-ce6c33245293&amp;ID={@ID}">Send Email</a>  </td>

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

So, in other words:



 

And there you have it! Again, be careful of GUIDs changing if you are moving sites around or updating workflows, but other than that this seems to work like a charm.

As always, your comments and feedback is always welcome.

Mark RackleyGuest Author: Mark Rackley
The SharePoint Hillbilly

Mark has been developing software applications for over 15 years filling the roles of Project Manager, Business Analyst, Lead Developer, and Software Architect.  He has been involved in projects for such companies as Dell, Motorola, Intel and Agilent Technologies. He has worked in large corporate environments, small software start-ups, and as a consultant.  Mark currently works for UNFI where he was introduced to the world of SharePoint and has taken on a lead SharePoint architect role within his organization making key development, administration, and architecture decisions.  Mark’s goal is to help ever new architect and developer avoid the frustrations and brick walls he ran into while learning SharePoint.

Blog:  http://www.sharepointhillbilly.com
Email: [email protected]
Twitter: http://www.twitter.com/mrackley

 

 

Please Join the Discussion

3 Responses to “Outing SharePoint Workflows – Linking to Workflows in List Views and Item Displays”
  1. erugalatha says:

    Any solution to this issue needs to work for Documents and InfoPath forms too. Otherwise you have an inconsistent way of start workflows depending whether the user is working with a List Item or a Document/InfoPath Form.

  2. Greg Schaefer says:

    Hey Mark,
    Really like both methods you describe to add the hyperlink to a workflow.
    Quick, elegant and simple.

    Another method (for pure end users with no access to SPD) would be to use Christophe at PathtoSharepoint ‘Text to HTML’ method and a calculated column. Successfully used it to generate an ‘Add to my Outlook’ hyperlink (see posts on STP – including some by Laura Rogers).
    Note that your method is much more straight forward b/c you don’t need to create a ‘dummy’ ID via workflow at item creation (SP not letting you directly use the ID field in calculated columns)

    Greg

    PS: There are some lines of text between the code sample and the last video (starts with csharpcode, .csharpcode pre ). guessing it is jst a typo?

  3. Sabrina says:

    I’m a workflow novice, but I’d figured most of this out on my own for a work project, and was able to mark issues list items as “Open” or “Resolved” using the link. However, I kept getting issues with the ID not passing properly after a list item had already been updated using the link. Discovered the error during a demo…oops.

    Thank you, Greg Schaefer for helping me learn that the [ID] field cannot be used in a calculated field. I created a second workflow to populate a “dummy” field in the list, and I’m getting 100% success rate on my tests now that I am using the dummy field instead of the [ID].

    I love EUSP…it has been the most useful SharePoint community I’ve found and has helped me, who has about 12 months of SP experience) look like a superstar! Keep up the GREAT work, team!


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!