Skip to main content

SharePoint 2013 - Start a Site Workflow using a Custom Action

In recent travels I've encountered what seems to be either a product limitation or a bug. After digging around some it appeared that I wasn't the only one facing this challenge, and unfortunately there wasn't a concrete enough solution or workaround out there. Hence the blog post hoping to save some of you the unnecessary hair-pulling which I had to endure.

My task was fairly simple; "Start a Site Workflow using a Custom Action button". The first part, creating a Custom Action, is trivial. This can be done in Visual Studio or SharePoint Designer. For the sake of simplicity I used SharePoint Designer.

Create a Custom Action button

  1. Start up SharePoint Designer 2013 and connect to the desired site.
  2. From the left navigation select Lists and Libraries.
  3. I'm using a simple list called "List One". Boring name, but easy to follow. :)
  4. Click on the list name to manage list settings.
  5. From the ribbon select Custom Action button then click View Ribbon from the drop-down menu.
  6. NOTE: The "View Ribbon" choice gives us the freedom to specify the section of the ribbon where action button will be placed. Other choices like Display/Edit/New Form Ribbon are used to launch those list form respectively.
  7. Next, a pop-up dialog prompts us to enter some info (i.e., Name, Type of Action, etc.).
  8. NOTE: Unfortunately this is where we run into problems. "Initiate workflow" drop-down menu does not show any of the existing workflow definitions or associations. Also, keep in mind this is the site collection root web, where all of my workflows are defined.

    Very strange. We move along, but we'll come back to this.
  9. In advanced options we specify Button Image URL and location of where the button will appear.
  10. NOTE: Either 16x16 or 32x32 size for the button image will work.

    Notice that in the Ribbon Location I'm placing the button inside the Workflow section of the ribbon.

    Sequence number is optional and it specifies the order of precedence in which the button will appear.
  11. Click OK to save changes
Let's navigate to our list to see how the new Custom Action button renders.
NOTE: Notice our Send E-mail custom action is placed inside the Workflow section of the server ribbon as we specified.

Create a Site Workflow

To ensure we stay focused on the context here, we'll create a workflow to send a simple E-mail. Again, we turn to SharePoint Designer to do this fairly quickly. This is what our Site Workflow looks like in the workflow text-based designer.
Again, we are not aiming for greatness here in terms of workflow complexity, just enough to demonstrate the functionality (or lack thereof) with a Custom Action.

Initiate Workflow via Custom Action

I promised we'd come back to this so here we are. Let's edit the Custom Action we created earlier so we can specify the "Initiate workflow" parameter.
  1. In SharePoint Designer, click on the Custom Action to edit it's settings.
  2. Select "Initiate workflow" radio button and click on the drop-down arrow.
If the Site Workflow actually shows up as an option in the drop-down then save yourself some time and stop reading. You're done! However, I'm confident you will continue reading as the drop-down menu appears empty.

The Workaround

It appears that by design "Initiate workflow" query returns only List Workflows. This means that any Reusable or Site Workflows that you may have defined/published will NOT show up in the drop-down as an option. Although not ideal, there is a workaround.

The trick is to use "Navigate to URL" as the workflow trigger instead. To do this successfully we will need to create an Initiation Form for the Site Workflow. Let's do that quickly.
  1. We open up the "Send E-mail" site workflow from earlier and select Initiation Parameters from the server ribbon.
  2. Association and Initiation Form Parameters dialog opens. Select "Add..." to proceed and choose a type of parameter. I'm simply using a Multi-line Text field called Comments.
  3. NOTE: Initiation Parameters are typically used when trying to collect some data from a user upon them manually starting a workflow. In this case we are using it as a trigger for our Custom Action button.
  4. Click Next to proceed.
  5. Enter a default value if you wish.
  6. Select Finish to create the parameter. If successful, the parameter shows up in the dialog.
  7. Click OK.
  8. Make sure to Save and Publish the workflow if you haven't already.
In the "Forms" section of the workflow information page you will notice a new form is automatically created (WFInitForm.aspx).
Now that the initiation form has been successfully created all that is left for us to do is edit the Custom Action button and populate the "Navigate to URL" parameter with the URL of the Initiation Form.
  1. Edit the Custom Action button using SharePoint Designer.
  2. Scroll down to the "Navigate to URL" section and click the Browse button.
  3. Navigate to the location of the Initiation Form.
  4. NOTE: Initiation forms are all stored inside the wfsvc directory located at the root web of the site collection.

    Each form resides within a folder named by the GUID of the respective workflow. Make sure you're selecting the correct workflow folder.
  5. Click OK, the once again to save changes to the Custom Action.

Let's Test

Let us navigate to the list where we created our Custom Action button and see how this works.
  1. Once there, click on the Items or Files tab from the server ribbon (depending on whether it is list or library), and click the Custom Action.
  2. If we did everything correctly, we should be redirected to the workflow Initiation Form.
  3. We click Start and await for the workflow to execute.
  4. Check your inbox.
Thanks for reading!

Comments

Popular posts from this blog

SharePoint 2013 - Simple Glossary using "HTML Form Web Part"

Introduction At some point you probably thought about incorporating glossary functionality as a part of a larger solution, or perhaps you were simply looking for providing a more intuitive way of filtering hundreds of items within a List or Library. Now there are countless web parts out there that you can either purchase or download from the SharePoint Store free of charge, and they all come with their own set of bells and whistles.  However, if you are looking at building one yourself, well look no further. To accomplish this we will need three major ingredients: SharePoint Page (either Wiki or Publishing will work) SharePoint List/Library with some content (Files/Items) HTML Form Web Part Let's Implement In this post I’m using a simple Wiki page, but you can also use a Publishing page as well.  We just need a canvas to display our glossary. I presume you already have a list or library that contains some content which is applicable to this concept.  I’m

SharePoint 2013 - Can't access the site externally in Internet Explorer ("Page cannot be displayed")

Synopsis Before we start talking about the problem let's understand the setup here.  We have a SharePoint 2013 intranet site that is also configured for access outside of the corporate network.  Employees use the same URL to visit the site both internally and externally via standard ports (80 and 443). Internal URL: http://sharepoint.domain.com Public URL: https://sharepoint.domain.com The site URL has been added to the Local Intranet zone in Internet Explorer for passing domain credentials. Alternate Access Mappings have been configured in such a way that if a user requests the site over HTTP they are automatically re-directed to HTTPS. Internal URL Zone Public URL for Zone https://sharepoint.domain.com Default https://sharepoint.domain.com http://sharepoint.domain.com Default https://sharepoint.domain.com Web application has been configured to use Kerberos protocol for authenticating incoming c

Remove Orphaned Web Parts - MissingWebPart

At some point you may have encountered an error like this while browsing through the SharePoint Health Analyzer or if you are attempting to test your content database (i.e., Test-SPContentDatabase) prior to mounting it. Message reads something like this: One caveat is that the log message never reveals the Location of the culprit web part.  Luckily we can utilize T-SQL to query the content database and reveal the location of the web part in question.   Query the Content Database To do this fire up the SQL Server Management Studio either locally from your machine or while logged on to the SQL Server back-end of your SharePoint farm, open up the new Query window and enter the following statement: USE < Content_Database_Name > SELECT AllDocs.SiteId,WebId, Webs.Title as 'Web Title', ListId, DirName,LeafName  FROM AllDocs    inner join AllWebParts on Alldocs.Id = AllWebParts.tp_PageUrlID  inner join Webs on Alldocs.WebId = webs.Id  WHERE AllWebParts.tp