Sharepoint Drop Down Context Menu Workflow Shortcut

It’s fairly simple to add custom menu options to the drop down context menu in sharepoint library/list views. One useful example maybe to provide a shortcut to start workflows, instead of opening the workflow page; selecting the desired workflow and clicking the Start button.

To do this we need to add some Javascript to the page. Edit the page and add a Content Editor Web Part, hide it by clearing its Layout / Visible on Page checkbox. Edit the Content Editor Web Part Source and insert the following Javascript:

<script language="javascript">

function Custom_AddDocLibMenuItems(m, ctx)
{
var strDisplayText = "Send for Review";
var strAction = "http://sharepointserver/Workflows/Send%20for%20Review/Send%20for%20Review.aspx?List=14987b66-90be-4693-aafd-94bc6ba8f18e&amp;ID=24&amp;TemplateID={dcbbce95-46dc-4b58-b69e-a99b9ea6a698}&amp;Source=http%3A%2F%2Fsharepoint%2Edomain%2Ecom%2FWIP%2FForms%2FOpen%2Easpx%3FPageView%3DShared";

var strImagePath = "";

var start = strAction.indexOf("&amp;ID=")+4
var prefix = strAction.substr(0, start)
var suffix = strAction.substr(strAction.indexOf("&amp;", start), strAction.length)

strAction = "location.href = '" + prefix + currentItemID + suffix + "'"

// Add our new menu item
CAMOpt(m, strDisplayText, strAction, strImagePath);

// add a separator to the menu
CAMSep(m);

return false;
}
</script>

If you update the workflow you will need to edit the strAction property as the URL will change. Also if you try to start a workflow using the shortcut on an item where the workflow is already running the workflow will error. If there is a way to check if workflow is running on an item I’d be interested to know how it’s done!

1 comments:

BeerThirty.com said...

I have been trying, unsuccessfully, to get this implemented. I add it, and change the URL to a workflow start, but it shows nothing on the page. Thoughts?