Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Currently when I click on a custom action to run a workflow on a selected item the browswer navigates away from the current page to display the initiation form. This wouldn't be a such a problem except that when I click start or cancel to move on the browser navigates back to the associated library NOT the page the browser originally displayed before starting the workflow.

This behavior is unfriendly. I need the browser to navigate back to the original page after starting/cancelling the workflow. It would also be acceptable for the initiation form to open in a modal dialog as long as it goes back to the original page when closed.

I have administrator access to the site I'm editing and I can make changes with SPDesigner 2010. I recently also got InfoPath2010 installed and if there's a way to do it there I would be most amenable to the solution.

I've scoured the files (*.xml, *.xoml, *.xsn, *.xom.rules) in the workflow's directory under 'All Files' in SPD2010 site browser but have found no xml/aspx options even vaguely resembling properties that might tell sharepoint how to open the form.

Any help you could share would be appreciated.

share|improve this question
    
Have you tried to add source to the link of your custom action? –  Alexander Mar 27 '13 at 7:21
    
The custom action starts a workflow. I'm not sure what you mean by "add source". The workflow starts, and then the browser navigates back to the library's AllItems.aspx. –  adnauseam Mar 27 '13 at 14:40
    
Are you referring to something like this? I've recently tried this and receive a javascript error when I click on the ribbon button claiming "invalid character" in sp.ribbon.js. This solution seems to be what I want yet I haven't yet got it to work as the author suggests it will. –  adnauseam Mar 27 '13 at 15:04
add comment

1 Answer

up vote 0 down vote accepted

Inspired by the page Custom SharePoint Context Action links and Modal Dialogs I will now proceed to answer my own question.

Using these pages as references:

SharePoint Javascript: Create a modal dialog
SharePoint current site base URL
Start a Workflow from item column
Get ID of Selected Item

The solution requires some sleuthing.

You'll need to know:

  1. The List or Library Guid. This can be found in the list properties area when viewing the list or library in SharePoint Designer. Also it's found in workflow initiation form URLs.
  2. The Workflow Guid. Again, this can be tricky to find. It's not listed anywhere in SharePoint Designer. I found mine by accident. It's often displayed in the workflow initiation URL.

To find these:

Make a custom action to initiate the workflow (hint: make sure it can be manually started), then click/select the ribbon/menu item to perform the custom action.

The URL appears in the browser's URL text box at the top.

Example workflow intiation URL:

http://<site url>/_layouts/IniWrkflIP.aspx?List={11449cc0-e482-4971-9ec7-f12e812f4489}&ID=56&TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}  

Notice in the middle of this URL there's a parameter passing the selected item's ID to the workflow. Without this the workflow will fail to start.

The List/Library GUID is here:

List={11449cc0-e482-4971-9ec7-f12e812f4489}&

And the Workflow ID is here at the end

TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}

Notice in the middle of this URL there's a parameter passing the selected item's ID to the workflow. Without this the workflow will fail to start.

ID=56&

SharePoint generates all three of these parameters internally when you click the custom action. We're going to use the List and Workflow IDs, and because the user will select any item in the list, we'll use Javascript to determine this ID.

The JavaScript:

Here is the bit of Javascript that will open a modal dialog displaying a workflow initation form for the currently selected item. Place this code into the "Navigate To Url" field of your custom action:

javascript:OpenPopUpPageWithTitle(L_Menu_BaseUrl + "/_layouts/IniWrkflIP.aspx?List={11449cc0-e482-4971-9ec7-f12e812f4489}&ID=" + SP.ListOperation.Selection.getSelectedItems(SP.ClientContext.get_current())[0].id + "&TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}", RefreshOnDialogClose, 600, 400, 'Assign To')  

Let's look at the code Piece by Piece

The first part should be obvious, this allows us to run chunk of javascript code. In this case we're using the OpenPopUpPageWithTitle method which seems to be SharePoint specific. See the 1st reference URL for more info on this method.

javascript:OpenPopUpPageWithTitle(  

Next the constant at the start of the first paratemeter, "L_Menu_BaseUrl", returns the site, or subsite base URL. This is an internal JavaScript constant that SharePoint creates. See the 2nd reference URL for more info.

L_Menu_BaseUrl +  

In the next part we're telling the method where within this site/subsite is the aspx page we want to display, and the parameters it needs to initiate a workflow for the selected item. The question mark denotes we're going to pass some parameters to the ASPX page.

"/_layouts/IniWrkflIP.aspx?  

The first URL parameter is the List or Library GUID.

List={11449cc0-e482-4971-9ec7-f12e812f4489}&  

The next URL parameter is the ID of the first selected list item. We interrupt the string literal so we can use some javascript to return the first selected item. See The 4th reference URL to learn a little bit more about this.

&ID=" + SP.ListOperation.Selection.getSelectedItems(SP.ClientContext.get_current())[0].id + "&  

The last URL parameter refers to the workflow itself. Make sure to close the string literal before we pass off the next OpenPopUpPageWithTitle parameter.

TemplateID={c810bee8-8799-40ac-a8db-d564a12c668d}",  

Afterwards there are four more parameters:

RefreshOnDialogClose, 600, 400, 'Assign To')  

The first part is the action we want the site to perform when the dialog is closed. There are likely many of these actions it just so happened that the site I found used the one I want as well.

RefreshOnDialogclose

The following two parameters give the width and height, in pixels, of the resultant modal dialog window.

600, 400,

The last one is the page title. I just used the title of the workflow.

"Assign To")

Summary

Now, when we select a list or library item and choose to perform a custom action (wherever it's configured to be) the workflow initiation displays in a user-friendly modal dialog window.

It's unfortunate that the only way to have the workflow initiate in a model dialog is by using this custom action 'hack' (as far as I know).

This helpful tip took me some hours of learning and investigating so I hope you find it useful. Enjoy.

share|improve this answer
    
The sad thing is that although this worked initially SharePoint generates a NEW ID for a workflow once it's republished. This ultimately creates too much maintenance in the long run. There are also issues, atleast at my end, with SharePoint designer disallowing me to choose the "Navigate to URL" option. If the workflow is allowed to be started manually then this option is automatically reset back to "Initiate Workflow". This confuses and befuddles me. SharePoint is a very powerful development platform but bugs and quirks like this have really forced me to take it less seriously. –  adnauseam Mar 27 '13 at 19:49
    
I've found that I'm also able to dynamically insert the GUID of the workflow as long as I know the name. That way, if I republish the workflow this custom action will still run the correctly. –  adnauseam Mar 27 '13 at 22:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.