El Blanco's Office 2007 Blog

Monday, December 10, 2007

A Bug with CustomAction in the Actions Menu

UPDATE 06-05-08: Check out a posting by The Kid who describes how to get around this issue using a web control instead of the UrlAction element.

UPDATE 12-12-07: I downloaded and installed SP1 for MOSS today, and this problem is still occurring, so it looks as if this wasn't fixed as part of SP1 - I'm still hoping someone will chime in with a brilliant workaround, but I'm not holding my breath :)

I've just found a very irritating bug when using CustomAction elements to extend the UI in MOSS, specifically when extending the Actions menu of a list although I haven't yet tried this with other menus such as the upload menu or settings menu . . .

I've got a custom action with the following definition:

<CustomAction
Id="BlancoWorld.ActionsMenuAddOn"
RegistrationType="List"
RegistrationId="101"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="0"
Title="Do something new">
<UrlAction
Url="~site/_layouts/BlancoWorld.ActionsMenuAddOn/
DoSomethingNew.aspx?List={ListId}
"/>
</CustomAction>

Now, as one would expect, an item is added to the Actions menu on document libraries (and only document libraries, because I've set the RegistrationType and RegistrationId attributes !). If I now navigate to this list, click on the Actions menu, and select my new item it works as expected – brilliant. Behind the scenes SharePoint is doing a little bit if clever trickery and replacing "{ListId}" with the actual GUID of the list in question – great. So the actual URL is something along the lines of:

http://yoursite/_layouts/BlancoWorld.ActionsMenuAddOn/
DoSomethingNew.aspx?List={d6c73378-906b-4c55-a078-33c1246d657c}

Now, drop a web part representing the same document library onto your site in SharePoint and configure it to have a toolbar type of "Full Toolbar" so that you get all the nice menus on there too such as the Actions menu where we've added our new menu item. Now click on the new menu item from this menu – disaster !! Unfortunately, for some reason that I can only think is a bug in the product, when you select this new Actions menu item from the web part on your site, SharePoint doesn't replace "{ListId}" with the list's GUID – it just simply leaves it as "{ListId}" which is of no use to anyone !! So your actual URL would be:

http://yoursite/_layouts/BlancoWorld.ActionsMenuAddOn/
DoSomethingNew.aspx?List={ListId}

Has anyone come up with away around this or know anything about whether this will be fixed in SP1 or not – because this is causing me a headache !!!