Initiate a SharePoint workflow from a button on the list view.

I came across a scenario recently where a project required that a list of items could have a button or link on a list view, which would cause a workflow to start.

Essentially the users involved were not happy using the out-of-the-box way that SharePoint (WSS 3.0) allows users to manually initiate workflows. They believed there were too many steps involved.

After a bit of searching, I came up with a method involving the use of a hyperlink column on the list in question, coupled with a very simple workflow. I will outline the steps involved in this process below. This is not the most graceful solution I am sure, but it is a simple solution to what can be a tricky problem.

How was it done?

Note: I am assuming that you have a simple workflow attached to a list, if not then please create a simple SharePoint Designer workflow. You can see how to do this here.

1. Add a new hyperlink column to your list, this is going to represent the button which users click on to start the workflow, so give the column an appropriate name.

2. Click on the list settings for your list and select ‘Advanced settings’, ensure that ‘Allow management of content types’ is set to ‘Yes’. This will allow us to hide the hyperlink column from the forms involved, if your list is a custom list then you may be able to go to ‘Form settings’ within list settings and make more detailed amendments to what appears on the new, display and edit forms.

3. In the ‘Content Types’ section of the ‘List Settings’ page, click on the content type for your list. Then click on the name of your column. On the ‘Change List Content Type Column’ page click on the radio button for ‘Hidden’. Click ‘OK’ and return to your list, you should see an empty space for your new column. However if you click on ‘New’ or try to edit an existing item your column should not display.

4. I have a simple workflow attached to this list. This basic workflow merely adds an entry to the workflow history list saying ‘Workflow started OK’. I assume your workflow is going to be slightly more complex, however the principle is the same. If you click on an item in your list (if you don’t have one then create a quick test entry), and select the ‘Workflows’ icon from the item toolbar. Now click on the name of your workflow.

5. You should now be looking at the initiation page which SharePoint Designer has created for us, now this page can be customised to say whatever you wish via SharePoint Designer, but I am going to leave it as the default for now. The important part here is the URL and parameters.

The URL of this page will be something similar to:

http://SITE URL/List Name/Workflows/Workflow Name/Workflow Name.aspx

and it should have 4 URL parameters, these are as follows:

The guid which identifies the list involved. This will not change for each link required on our list.

The numerical ID of the list item involved. This is the key to making this process work.

The guid of the workflow to be initiated. This will not change for each link required on our list. Note: This guid, unlike the list guid above requires the braces {}, though these may be url encoded (so don’t be surprised to see the guid starting %7B which is { when URL encoded).

The referring URL, responses will be redirected back to here once the workflow is successfully started.

You can probably see that we could manipulate this URL to generate a link for our new hyperlink column by simply altering the ID parameter being sent to this page. How can we do this? We simply use another workflow!

6. Ensure you have copied the URL from step 5 to the clipboard. Open SharePoint Designer and create a new workflow for this site. This simple workflow should be set to ‘Automatically start this workflow when a new item is created’ only.

7. Click ‘Next’ and then add a ‘Build Dynamic String’ action click on ‘dynamic string’ and paste your URL into the ‘String Builder’ window. Find the ID parameter and delete the value which you had pasted in. Leaving the cursor in this location click on ‘Add Lookup’ and select the ‘ID’ column of the ‘Current Item’.

Click ‘OK’. Your URL should now look similar to that shown above. At the end of the URL add a comma (,) followed by the text which you want your hyperlink column to display in the list view. For example I have added ‘, Start my workflow’. There must be a space between your comma and your link text. Otherwise you will get the entire URL as the text for your hyperlink!

Click ‘OK’ again.

8. Add another action to ‘Update List Item’ and with Current Item selected click on ‘Add’. The ‘Value Assignment’ dialog will allow you to assign your new hyperlink column to the value of the URL string we have just generated. Select your new hyperlink column from the ‘Set this field:’ list. Next to the ‘To this value:’ list select the ‘fx’ button. In the ‘Source:’ drop down select ‘Workflow Data’ and in the ‘Field:’ select your variable (probably named with the default ‘Variable: variable’)

Click ‘OK’ then ‘OK’ again on the ‘Value Assignment’ dialog. The ‘Update List Item’ dialog should now show this field and value in the list of items to be updated. Click ‘OK’ again.

9. We can now click ‘Finish’ to complete our simple workflow. SharePoint Designer will now generate the required files and bind this workflow to your list.

10. Go to your list and click on ‘New’ in the list toolbar, complete a test item (noting that your hyperlink column is not listed). Click ‘OK’ and you should return to your list view and your hyperlink column should be populated with the display value you entered in stage 7.

Clicking on this hyperlink should take you to the initiation page that SharePoint Designer created for you, but (crucially) the ID will be the ID for the item which the hyperlink column exists on.

Clicking ‘Start’ on this page will start your workflow as designed in SharePoint Designer.

So there you go! Wait for it.There are a few buts.


1. Document Libraries with check in/out enabled
This is the same as designing any workflow which is going to update these items, you must handle checking in/out. Because our workflow is only initiated on creation then this is not a major issue. I did come across some problems in this scenario, but they were overcome by having the workflow check the item back in before updating.

2. Custom Workflow
This workaround is designed for dealing with either SharePoint Designer workflows or custom workflows which use an initiation form as SPD always creates a workflow initiation form anyway. It will not work for custom workflows that do not require an initiation form as there is no URL to link to (This is a scenario that I am interested in so if anyone has any recommendations then please post a comment). If your custom workflow uses an InfoPath form to initiate then you might want to look at creating links to the following URL:

http://SITE URL/_layouts/IniWrkflIP.aspx

This page takes similar parameters to the SPD generated page except you can supply an xsn location for your InfoPath form too. More information can be found here. The above technique should work perfectly well in this scenario, I just haven’t tried it.

1555-ANTS_60x60_Logo_CP.gif How does your SharePoint application perform? The Beta release of ANTS Performance Profiler 8 adds support for SharePoint 2013, helping rapidly identify and understand SharePoint performance issues. Try the Beta.