1,804 articles and 14,678 comments as of Saturday, February 19th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Tuesday, February 2, 2010

Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010

Guest Author: Geoff Varosky

In SharePoint 2010, it is easier than ever to add custom actions that are scoped to a specific list using SharePoint Designer 2010. So today, I am going to walk you through the process.

In a related post on my blog, I showed you how to surface ULS logs using SharePoint Designer 2010, an External Content Type, and an External List. We’re going to use that list as our base for our custom action.

Our phony business case for this custom action is such – We are surfacing our ULS logs into a SharePoint list, and want to collect feedback on specific log entries for later consumption. We need to link to a form elsewhere in the site, which we will pass a reference to the item in question, as a URL.

Note – the List Item Menu refers to the same thing as the Edit Control Block. This is the context menu which is associated with all list items, available in list views and list view web parts.

So, let’s open SharePoint Designer 2010, and navigate to our ULS Logs list, and we’re going to select Custom Action > List Item Menu from the Custom Action button on the ribbon UI


Once we select that link, we are presented with the following form


We’re going to name our custom action Log Entry Comment, and give it a description as well. Now let’s scroll down. You will see that we have 3 different types of actions we can associate with this custom action…


We can

    • Navigate to a Form for this list
    • We can Initiate a Workflow
    • Or, we can Navigate to a URL

We’re going to select Navigate to URL, and enter in our URL, and enter in our bogus URL, and pass a name/value pair of ItemURL={ItemUrl}, which was found by looking into the November 2009 version of the SharePoint 2010 SDK


OH NO! We can’t use it in Beta 2, which is the public beta we are running! Ok, so I guess on the receiving end, we’ll need to fix it up in some other way. So, we’ll just change our URL to pass a few things, and build the URL ourselves.

http://www.grace-hunt.com/ULSLogComments?ItemURL={SiteUrl}/Lists/ULS Logs/DispForm.aspx?ID={ItemId}

there, that should do the trick…

So, set your URL, and then give it a sequence number. This is the number in which it appears in the list. Anything over 10000 is a good practice, so you do not interfere with any other items in the list.


Then click OK, and you now have a custom action, associated with a list item, all without cracking open Visual Studio, deploying a package, etc. etc.

You will now see it on the ULS Logs list dashboard page in SharePoint Designer 2010


So, let’s go check out list… and there we have it, our custom action, associated to the list item menu/edit control block, within our list!


And if we click it, we get an ugly, url encoded version (http://www.grace-hunt.com/ULSLogComments?ItemURL=http%3A%2F%2Fsp2010dev%2D01/Lists/ULS Logs/DispForm.aspx?ID=__cb40004300o4200b7983a57-53e7-de11-8ed4-000c29a9d0f1) of:

http://www.grace-hunt.com/ULSLogComments?ItemURL=http://sp2010dev-01/Lists/ULS Logs/DispForm.aspx?ID=__cb40004300o4200b7983a57-53e7-de11-8ed4-000c29a9d0f1

Another cool thing, which you may notice, is that ALL list items have a globally unique identifier in SharePoint 2010! YES! No more list item IDs starting with 1, and going up from there.

Guest Author: Geoff Varosky
Company: Grace-Hunt, LLC.
Blog: http://www.geoffvarosky.com
Twitter: @gvaro

Geoff Varosky (MCP, MCTS) is a Senior Solutions Developer for Grace-Hunt, LLC (http://www.grace-hunt.com), a Microsoft Gold Partner focusing on SharePoint and Dynamics Solutions based out of Hudson, MA. He has been architecting and  developing web based applications for over a decade, and has been working with SharePoint Technologies for the past 6 years. Geoff is an active member of the SharePoint community, and speaks regularly at SharePoint events and user groups, and maintains a blog on SharePoint at http://www.geoffvarosky.com.

 

Please Join the Discussion

18 Responses to “Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010”
  1. Jeff Jones says:

    Great post Geoff. Very practical, thank you. I’m still getting used to the layout of SPD and finding the basic buttons in 2010.

    Did you mean 1,000 for sequence? The text has ten thousand but image only one. The GUID number for list items (instead of ID int) may through a monkey wrench at some people’s customizations (JS?) post migration but sounds like a smart long term move.

  2. Thanks for the comment Jeff!

    I actually used a bad example in my screenshot – should be 10k, not 1k. Thanks for noticing that. Consider this reply errata for this article :)

    I do believe that the identifiers will slip a few people up when migrating to 2010, however, unique identifiers for list items OOTB is something that I have been wishing for, among other things, in the new product, and it appears that my wish has been granted!

  3. Alex says:

    This is a great post. Thanks.

    What if I want to make this link go directly to any associated items in another list and the association is a Title field?

    For example you have the url: http://www.grace-hunt.com/ULSLogComments?ItemURL={SiteUrl}/Lists/ULS Logs/DispForm.aspx?ID={ItemId}

    Would I change the url to something like: http://MYSPSITEURL/Lists/DESTINATIONLIST/EditForm.aspx?ID={Title}

    In this example the title would be a numeric field that coincides to the ID of the destination list.

    Any ideas?

  4. Alex,

    Thanks for the comment. Through SharePoint Designer 2010, you would not be able to achieve this. The tokens available are limited to ItemId, ItemUrl, ListId, SiteUrl, and RecurrenceId. If you go the code route however, this could be achieved through binding the CustomAction to an assembly.

    • Alex says:

      Can you point me in the right direction for how to bind a CA to an assembly in SP2010?

      • Alex,

        Unfortunately you cannot bind an assembly to an ECB menu item, however, you can do it through toolbars, ribbon options, etc.

        Thinking about this a bit more, you could also possibly do this through some javascript and substitution. Possibly by putting some sort of text, such as XXREPLACEXX, or something at the end, and then using javascript to copy the title field from the page, or, do a lookup back to the list for that, and replace it with the title.

        There are quite a few ways to skin a cat in this instance.

  5. Filbert says:

    Hi Geoff,

    Came across your post when looking for creating custom action in an external list. I was able to add the custom action successfully. Now, the scenario I am facing is that the end users want to have the custom action as the default action. In other words, they want to get rid of the default items of the List Item menu (Edit, View Item) and have this custom action as the default action to happen when the user clicks on the hyperlink. Any pointers on how to accomplish this would be very helpful.

  6. Mark says:

    Great post….do you have any information or instruction for creating a custom list item group where I can have multiple custom list actions contained within. Also, I noticed while trying to work with the sequencing, using 10000 places the custom list item at bottom of default option however using 1000 places the custom item in between a few of the default options. Can you provide any guidance also on using ‘Sequence options’ for Custom Action list items? Thanks a bunch

    • Mark – I’ll take it from bottom to top.

      Eric Kraus wrote a great powershell script which I make use of often, which will generate a list of all custom actions contained within your farm. This can be found here: http://blogs.msdn.com/b/ekraus/archive/2010/05/03/list-all-customactions-in-the-farm.aspx

      You can then single out what location/group/etc. you are using to find out what is there already, and sequence yours accordingly.

      Now – if you have the same sequence number as another custom action, whichever one comes first alphabetically within the features directory is going to go first. They will not cancel each other out.

      As for grouping list item menu options – this cannot be accomplished through CustomActionGroup unfortunately. You may want to check over at Jan Tielen’s blog – http://weblogs.asp.net/jan/ I am fairly certain he did have a post on it a while back as far as how to do it.

  7. ads says:

    god, sharepoint sucks so hard. using a guid instead of a decent id is as braindead as it gets.

  8. Gary says:

    Thanks Geoff.
    We just got SharePoint and are learning all the tricks. Next is to make the button dependent on a field, but this was a great starter as was your other post.
    Thanks so much.

    Gary

  9. Sorry everyone – it appears I owe a lot of people, a lot of replies from here. These were ending up in my junk mail folder. Let me start from the bottom up!

Trackbacks

Check out what others are saying about this post...
  1. [...] Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010 [...]

  2. [...] my last article, Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010, We walked through the process of adding custom actions to the List Item Menu using SharePoint [...]

  3. [...] Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010 [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!