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

SharePoint 2010 question here. I have a document library with a number of documents, and I want to add an entry to the list item context menu (the dropdown menu that contains the "View properties"/"Edit properties" etc). I got the impression that this could be done by adding a content editor web part containing the following JavaScript:

<script language="javascript">

function Custom_AddDocLibMenuItems(m, ctx)

{
  var strDisplayText = "Custom menu item";
  var strAction = "alert('Yo')"; 
  var strImagePath = "";

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

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

  // false means that the standard menu items should also be rendered
  return false; 

}

</script>

...as per http://blogs.msdn.com/b/bowerm/archive/2004/07/07/175691.aspx. This code adds a new context menu item, as expected. However, I need the context of the item which was clicked in order to access a specific column of the list item. The end goal is to provide a custom filter URL to a different list which is based on the selected item.

The context information is supposed to be available through the itemTable object. But for some reason, this item is not available either through the Custom_AddDocLibMenuItems body or strAction. Any ideas?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

In SharePoint 2010 you can use SharePoint Designer to add custom actions. The following article explains how to add custom action for an external list but the procedure is the same for any other list.

With custom actions you can open a list form of the current list, open a different URL or initiate a workflow, however AFAIK you cannot call a JavaScript if that was your intention here.

share|improve this answer
    
Thanks, this is a step in the right direction. However, I still need access to the contents of the selected list item..just getting the item ID isn't sufficient. Specifically, I need the contents of the field "History". Do you from the top of your head know how to do this? –  Geir Smestad May 30 '11 at 8:12
    
Ok, ended up pointing the custom action to an aspx page which reads the list item ID as an URL parameter and then forwards to the appropriate URL. Sort of hackish, but works well enough. Thanks for the tip about using SharePoint designer in SP2010, this makes everything a lot easier. –  Geir Smestad May 30 '11 at 9:15
add comment

As Toni say, Custom Actions is the way to go.

If you want to access the context menu on items in a list, you need to define that as location for your custom action manifest. As far as i remember this is the ECB (EditControlBlock) location.

Here is a list of all custom action locations.

share|improve this answer
add comment

It seems you want to fetch the value of the History field using Javascript. You might want to use the ListData.svc for that purpose. Although the code below needs to be modified to retrieve it for the selected value, you should get the general idea from it:

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $.getJSON("http://yourserver/_vti_bin/ListData.svc/YourListName/",function(data) {
      $.each(data.d.results, function(i,result) {
        var history = result.History;
      });
    });
  });

The link provided in the previous answer from someone else is really not the definitive list to all custom action ids.

I would suggest to dowload the spreadsheet from my blog post at: Download Custom Action Ids spreadsheet

Finally, I suppose you only want to add this specific piece of functionality to one document library else I would suggest to build a feature (download CKSDev for VS2010 to make things easy) and think about adding a custom action that contains a scriptlink to inject your clientside stuff.

share|improve this answer
    
REST is an option, but you can also use Client Object Model to access list data –  Ivan Padabed May 30 '11 at 14:27
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.