SharePoint 2010 Custom Action EnableScript function - sharepoint

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.

Related

CRM 2011 Ribbon CheckBox Checked by Default

How can a checkbox on the ribbon be checked by default?
There does not appear to be an attribute mentioned on MSDN.
Can it be done with JavaScript?
I have a checkbox on the queue view, which while checked should keep the queue auto refreshing:
<CustomAction Id="Mscrm.HomepageGrid.queueitem.MainTab.Workflow.Controls.CustomAction" Location="Mscrm.HomepageGrid.queueitem.MainTab.Management.Controls._children" Sequence="60">
<CommandUIDefinition>
<CheckBox Id="Mscrm.HomepageGrid.queueitem.MainTab.Workflow.Controls.CheckBox" LabelText="Auto Refresh" TemplateAlias="o3" ToolTipTitle="Queue Auto Refresh" ToolTipDescription="Periodically auto refresh this queue" Command="Mscrm.HomepageGrid.queueitem.MainTab.Workflow.Controls.Command" Sequence="60" />
</CommandUIDefinition>
</CustomAction>
The auto-refresh is working fine and is on by default.
I'm not certain but I believe the Microsoft Ribbon between application is fairly similar.
So you could try; CheckBox element: ApplicationDefaults.IsChecked
This is total guess in all honesty

Custom Action for specific list view - SharePoint 2010

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();"
/>

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>

Resources