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.
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.
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
- Start up SharePoint Designer 2013 and connect to the desired site.
- From the left navigation select Lists and Libraries.
- I'm using a simple list called "List One". Boring name, but easy to follow. :)
- Click on the list name to manage list settings.
- From the ribbon select Custom Action button then click View Ribbon from the drop-down menu.
- Next, a pop-up dialog prompts us to enter some info (i.e., Name, Type of Action, etc.).
- In advanced options we specify Button Image URL and location of where the button will appear.
- Click OK to save changes
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. |
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. |
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. |
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.
- In SharePoint Designer, click on the Custom Action to edit it's settings.
- Select "Initiate workflow" radio button and click on the drop-down arrow.
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.
- We open up the "Send E-mail" site workflow from earlier and select Initiation Parameters from the server ribbon.
- 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.
- Click Next to proceed.
- Enter a default value if you wish.
- Select Finish to create the parameter. If successful, the parameter shows up in the dialog.
- Click OK.
- Make sure to Save and Publish the workflow if you haven't already.
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. |
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.
- Edit the Custom Action button using SharePoint Designer.
- Scroll down to the "Navigate to URL" section and click the Browse button.
- Navigate to the location of the Initiation Form.
- Click OK, the once again to save changes to the Custom Action.
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. |
Let's Test
Let us navigate to the list where we created our Custom Action button and see how this works.
- 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.
- If we did everything correctly, we should be redirected to the workflow Initiation Form.
- We click Start and await for the workflow to execute.
- Check your inbox.
Comments
Post a Comment