Tuesday, October 20, 2009

How To: Add Custom Menu Item in Context Menu (MOSS 2007).


Sometimes, you may have to add new custom menu item in the SharePoint list context menu. See the below image for an example:



(click image to enlarge)

This can be achieved through the "Content Editor Webpart".

1. Open SharePoint Designer.
2. Open SharePoint site (ex: http://172.16.10.10:2002)
3. Go to that specific page and edit that page
4. Click on "Task Panes" in SharePoint  Designer and open "ToolBox"
5. In the "ToolBox" pane, explore "Webparts" title.
6. There, you can see a hyperlink as "Open the webparts task pane". Click on it.
7. Insert the "Content Editor Web Part" from the newly opened task pane.
8. Write the below code inside the "Content" tag of the "Content Editor Web Part".

Code:
&lt;![CDATA[<script language="javascript">
/*
* @ Desc: Adds a custom menu items into the menu
*/
function Custom_AddListMenuItems(m, ctx)
{
 var str = currentItemID; 
 var strDisplayText = "Navigate Project workspace";
 strUrl = "Default.aspx";
 var strImagePath = "";
 strAction = "STSNavigate('http://" + location.host + "/ItemWorkspaces/Project/"+ strUrl+"')"; 
 // 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 rendered
  return false;
}
</script>]]>

See the below image, that will explain how i have added the code into the Content Editor Web Part.




Thats it....

No comments:

Post a Comment