views:

527

answers:

1

I'm adding a custom context menu item to documents (and not folders) in a SPDocumentLibrary list in SharePoint. The following code works, but always adds my custom menu item at the top of the context menu, which I don't want. I was guessing that the final parameter in CAMOpt was a sequence number that would define the order, but it doesn't seem to have any effect. Does anyone know if it's possible to add a custom context menu item to the bottom on the list?

function Custom_AddDocLibMenuItems(m, ctx) {
    var otype = currentItemFSObjType = GetAttributeFromItemTable(itemTable, "OType", "FSObjType");
    if (otype != 1) {
        var itemId = GetAttributeFromItemTable(itemTable, "ItemId", "Id");
        var listId = ctx.listName;

        var action = 'Go_To_Page("' + ctx.HttpRoot + '/_layouts/custom/PAGES/mycustompage.aspx?ListId=' + listId + '&ListItemID=' + itemId + ');';
        CAMOpt(m, 'Custom Menu Item', action, '/_layouts/custom/IMAGES/action.gif', '', 110);
        CAMSep(m);
    }
    return false;
}

function Go_To_Page(page) {
    window.location = page;
}
A: 

Is there any reason why you aren't able to use a custom action feature? For example use feature element code similar to the following but amend the Sequence number of the CustomAction element to locate the menu option:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    <CustomAction
     Id="DoSomething"
     RegistrationType="ContentType"
     RegistrationId="0x0101"
     Location="EditControlBlock"
     Sequence="10001"
     ImageUrl="/_layouts/images/action.gif"
     Title="Do Something">
     <UrlAction Url="~site/_layouts/custom/PAGES/mycustompage.aspx?ListItemID={ItemId}&amp;ListId={ListId}" />
    </CustomAction>
</Elements>

Setting the content type should ensure the feature doesn't apply to folders. If for some reason it is showing and there appears to be no way to disable it, you could use JavaScript/jQuery to hide the menu option from folders.

Alex Angas