Custom Action for specific list view - SharePoint 2010 - sharepoint

How can I target custom ribbon action menus for specific list views? I want to be displayed in the default view of the list but to be hidden in the other views.
Any ideas?

Though the question is old, yet unanswered , I am responding to it.
Create an empty Sharepoint Project in VS2010 , add an Elements.xml file in the project and past following XML in it.
<CustomAction Id="MyCustomButton" Sequence="999"
GroupId="Manage"
Location="CommandUI.Ribbon" // Location to display button
RegistrationId="101" // on every list, for a specific list or library put the GUID of list here e.g. RegistrationId="{GUID_OF_LIST}"
RegistrationType="List"
Rights="ManageWebs"
Title="Custom Document Library Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.Controls.CustomButton" TemplateAlias="o1"
ToolTipDescription="Creates a server side action."
ToolTipTitle="SSRibbon" LabelText="SS Action"
Image32by32="/_layouts/images/ContractClaims/newproject.jpg"
Image16by16="/_layouts/images/ContractClaims/newproject.jpg" Alt="New Project"
Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
Sequence="20"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
CommandAction="javascript:alert ('Hello World' ) ;" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
The several locations to display the button can be found here.For more on the top you can google respective XML elements.

You can use EnabledScript parameter in CommandUIHandler, where you can put javascript code and check if specific page/list/view is loaded.
link to similar answer
Example:
<CommandUIHandler
Command="Ribbon.ListItem.CustomGroup.Controls.BtnSayHello.Command"
CommandAction="javascript:alert('Hello');"
EnabledScript="javascript:
function isEnable(){
if(location.href.indexOf('AllItems.aspx') > 0){
return true;
}
return false;
}
isEnable();"
/>

Related

SharePoint 2010 Custom Action EnableScript function

I added a custom action to SharePoint list. In CommandUIHandler in EnableScript attribute I added a javascript function. Then I realised that it is being invoked twice. To be more specific:
1) When I enter a default view for the list and click "Items" in a Ribbon it is invoked once
2) When I select checkbox near the list item it is invoked twice?
I have some queries loading in a background so I don't want it to be called twice. Does anyone know whether it's a bug or SharePoint default behaviour?
<CustomAction
Id="Ribbon.Documents.TestGroup.AssignCard"
Location="CommandUI.Ribbon"
RegistrationId="10001"
RegistrationType="List"
ShowInLists="TRUE"
Sequence="26">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
<Button
Id="Ribbon.Documents.TestGroup.AssignCard"
LabelText="Assign"
ToolTipTitle="Assign a free card"
ToolTipDescription="Opens a form to assign a free card to a guest."
Alt="Assign"
Sequence="31"
Command="AssignButtonCommand"
Image32by32="/_layouts/1033/images/formatmap32x32.png"
Image32by32Top="-160"
Image32by32Left="-288"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="AssignButtonCommand"
CommandAction="javascript: document.ReceptionRibbon.AssignButton({SiteUrl}, {SelectedItemId});"
EnabledScript="javascript: console.log('1'); document.ReceptionRibbon.EnableAssignButton();" />
</CommandUIHandlers>
</CommandUIExtension>
I managed to solve the issue by setting a temporary boolean variable to false when query starts, and setting it back to true when it ends.

In SharePoint how to display custom ribbon button to particular lists only?

I am having four external list "List1", "List2", "List3", "List4". I have added a custom ribbon button Like:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="ATEAgWorkOrderButton"
RegistrationType="List"
RegistrationId="600"
Location="CommandUI.Ribbon">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.ListItem.Actions.Controls._children">
<Button
Id="Ribbon.ListItem.Actions.ATEAgWorkOrderButton"
Alt="Click on this button to Add"
Sequence="3"
Image32by32="/_layouts/Images/Project/image.png"
Command="ATEAg_WorkOrder"
LabelText="Add Detail"
TemplateAlias="o2"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="ATEAg_WorkOrder"
CommandAction="javascript:alert("Hello Success");" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
The button is now visible in all the external lists. But I want to make it visible for only "List1" and "List2". How to do this?
You need to explore the Andrew Connell's Ribbon Customization Deep Dive.
http://www.andrewconnell.com/blog/archive/2011/04/16/sharepoint-2010-ribbon-customization-deep-dive.aspx
He goes into how to solve these problems. In short instead of binding a customization for all lists of a certain type, you can register a javascript function that gets called to determine if you button should be shown or hidden. In this function you can determine which list is currently active.
If all your lists are associated with a ContentType, you can set the registration id of the custom action to the ContentType id.
From MSDN:
RegistrationID: Optional Text. Specifies the identifier of the list or
item content type that this action is associated with, or the file
type or programmatic identifier (ProgID).

SharePoint - CustomAction isn't showing on toolbar for a content type

I've created a feature with a content type:
<ContentType ID="0x01007C963A8770A24bbfBDBCE157B96EE769"
Name="Send" Group="Demo" Version="1">
</ContentType>
I want to create custom actions for this content type.
This works on the ECB (the popup menu of every item's title):
<CustomAction
Id="Demo.Send.PopupMenu"
Title="Send"
Location="EditControlBlock"
Description="Hold"
RegistrationType="ContentType"
RegistrationId="0x01007C963A8770A24bbfBDBCE157B96EE769">
<UrlAction Url="http://www.google.com/search?q={ItemId} Cookies"/>
</CustomAction>
However, I can't get it to work on forms' toolbars (edit or display):
<CustomAction
Id="Demo.Send.DisplayFormToolbar"
Title="Send"
Location="DisplayFormToolbar"
Description="Send"
RegistrationType="ContentType"
RegistrationId="0x01007C963A8770A24bbfBDBCE157B96EE769"
Sequence="108">
<UrlAction Url="http://www.google.com/search?q={ItemId} Cookies"/>
</CustomAction>
I don't get any error message, I just can't see the button.
It is working if I change the RegistrationId to 0x01, but then I see it on all content types (all items, really).
Any idea what's wrong with this code?
I seem to remember there being issues with content types when they didn't have all capitals in the identifier, both for the definition and when using.
Try
RegistrationId="0x01007C963A8770A24BBFBDBCE157B96EE769"
But completely remove the everything that refers to the content type. (or try a new one)

Sharepoint 2007 - custom context menu for certain file types

I was wondering if someone could help me out with Sharepoint 2007. What I want to do is to add a custom menu item to a context menu (the menu that opens when you click a document or another item).
Right now, the menu looks like this:
picture
I want to add an item, "Do stuff" for example, to this menu. Major problems:
I wish this item to appear only in menus for a certain file type (e.g. only for .html but not for .doc);
When I click this item ("Do stuff"), I want to call custom external code (written in C#, either an exe or a DLL), which accepts the name of the clicked file as an input parameter.
I understand the way to achieve this is by using Custom Actions (no javascript editing required in 2007, right?). But since I'm quite new to MOSS, I'm a bit lost and not sure what exactly to do and where to start, so any help is greatly appreciated.
You have to implement a CustomAction like this:
<CustomAction
Id="YourUniqueId"
Location="EditControlBlock"
RegistrationType="FileType"
RegistrationId="html"
Sequence="20"
Title="The text you want">
<UrlAction Url="~site/_layouts/company/ActionPage.aspx?List={ListId}&ID={ItemId}" />
</CustomAction>
What you put in the Url of UrlAction depends on what you want to do. It can be JavaScript or the url of a Page or Handler.
In my example it's a Page which gets the QueryParameters so that SPContext.Current.ListItem will contain the selected documents listitem.
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="d0574a32-59ce-4561-9496-ccf17da37a35" xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="Test2"
Location="EditControlBlock"
RegistrationType="FileType"
//docx = documents, txt = text files, html = html files**
RegistrationId="docx" Sequence="10"
Title="View Item Properties">
<UrlAction Url="~site/_layouts/WSSHOL/ViewPageRedirect.aspx?listid={ListId}&itemid={ItemId}" />
</CustomAction>
</Elements>

ListViewWebPart problem with custom Event list template

I have copied C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\EventsList\Events\schema.xml into a custom list template feature. I have another feature that creates the list instance:
<ListInstance
FeatureId="58c1f9c9-eadb-41dd-a358-e04b2f2e30c0"
TemplateType="100322"
Title="$Resources:core,calendarList"
Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder"
OnQuickLaunch="TRUE">
</ListInstance>
and then places a ListViewWebPart on the page:
<View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder" BaseViewID="0" WebPartZoneID="TopRightRow" WebPartOrder="3" />
I activate the features and go to the site. The webpart says: There are currently no upcoming events. To add a new event, click "Add new event". I click Add new event, enter the information, and click Save. The page refreshes, the no upcoming events message disappears, but there are no items displayed! If I go to the calendar the list item is there. What gives?
I change the list instance definition so that it uses the out of the box template:
<ListInstance
FeatureId="00bfea71-ec85-4903-972d-ebe475780106"
TemplateType="106
Title="$Resources:core,calendarList"
Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder"
OnQuickLaunch="TRUE">
</ListInstance>
When I rebuild the site, activate the features, and repeat the "add new" steps, the item is now displaying properly in the webpart after the page refresh.
I've backed out all of my changes from the custom list template. It is now identical to the OOTB schema. Why doesn't my custom list template work, but the OOTB list template does?
I have know idea why the OOTB template works, but I was able to fix my custom template.
First, remove the XslLink line from the BaseViewID="0" View in schema.xml:
<XslLink>main.xsl</XslLink>
Scroll down to the Toolbar/IfHasRights section. Change Case 4 from:
<Case Value="4"><HTML><![CDATA[<div class="tb"><img src="/_layouts/images/caladd.gif" alt="" /> <a class="ms-addnew" id="idHomePageNewEvent" href="]]></HTML>
<URL Cmd="New" /><HTML><![CDATA[" onclick="javascript:NewItem(']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<URL Cmd="New" />
</ScriptQuote><HTML><![CDATA[', true);javascript:return false;" target="_self">]]></HTML><HTML>$Resources:core,AddNewEvent;</HTML><HTML><![CDATA[</a></div>]]></HTML>
</Case>
to:
<Case Value="4"><HTML><![CDATA[<div class="tb"><img src="/_layouts/images/caladd.gif" alt="" /> <a class="ms-addnew" id="idHomePageNewEvent" href="]]></HTML>
<URL Cmd="New" /><HTML><![CDATA[" onclick="javascript:NewItem2(event, ']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<URL Cmd="New" />
</ScriptQuote><HTML><![CDATA[');javascript:return false;" target="_self">]]></HTML><HTML>$Resources:core,AddNewEvent;</HTML><HTML><![CDATA[</a></div>]]></HTML>
</Case>
This enables the new SharePoint 2010 popup NewForm.aspx behavior.
Next, change the provisioning of the webpart to:
<View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder" BaseViewID="0" WebPartZoneID="TopRightRow" WebPartOrder="3">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
<Title>Calendar</Title>
</WebPart>
]]>
</View>
This along with the removal of the XslLink line forces the webpart to render as a ListViewWebPart instead of as an XsltListViewWebPart.
Now the rendering between the two weparts is different, so as a last step, use the following style so that the add new link of the ListViewWebPart looks like the add new link of the XsltListViewWebPart:
div.tb {
border-top:1px solid #EBEBEB;
margin:3px 0 16px;
padding:9px 7px 3px 10px;
}

Resources