Answered by:
Disable or Display the New and Add Existing button in Ribborn.

Question
-
I try to disable the Add Existing button, just like I configurate xml for custom button I ever done before.
The following is my fragment of Xml:
---------------------------------------------------------------------------------------------------------------------
<CustomAction Id="Mscrm.SubGrid.salesorder.AddExistingStandard.CustomAction" Location="Mscrm.SubGrid.salesorder.AddExistingStandard">
<CommandUIDefinition>
<Button Id="Mscrm.SubGrid.salesorder.AddExistingStandard" Command="Mscrm.AddExistingRecordFromSubGridStandard" Sequence="30" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.AddExisting" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddExisting" Image16by16="/_imgs/ribbon/AddExistingStandard_16.png" Image32by32="/_imgs/ribbon/AddExistingStandard_32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddExistingStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddExistingStandard_ToolTipDescription" />
</CommandUIDefinition>
</CustomAction>---------------------------------------------------------------------------------------------------------------------
<CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridStandard">
<EnableRules>
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
<EnableRule Id="Mscrm.AddExistingRecordFromSubGridAssociated.Enabled.Custom"/>
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.AddExisting" />
<DisplayRule Id="Mscrm.HideAddExistingThroughOpportunityForQOI" />
<DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.CanWriteSelected" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="SelectedControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>---------------------------------------------------------------------------------------------------------------------
<DisplayRule Id="Mscrm.AddExisting">
<ReferencingAttributeRequiredRule Default="false" InvertResult="true" />
</DisplayRule>
<DisplayRule Id="Mscrm.HideAddExistingThroughOpportunityForQOI">
<FormEntityContextRule Default="false" EntityName="opportunity" InvertResult="true" />
</DisplayRule>
<DisplayRule Id="Mscrm.AppendToPrimary">
<EntityPrivilegeRule AppliesTo="PrimaryEntity" PrivilegeType="AppendTo" PrivilegeDepth="Basic" />
</DisplayRule>
<DisplayRule Id="Mscrm.AppendSelected">
<EntityPrivilegeRule AppliesTo="SelectedEntity" PrivilegeType="Append" PrivilegeDepth="Basic" />
</DisplayRule>
<DisplayRule Id="Mscrm.CanWriteSelected">
<EntityPrivilegeRule AppliesTo="SelectedEntity" PrivilegeType="Write" PrivilegeDepth="Basic" />
</DisplayRule>
<DisplayRule Id="Mscrm.ShowForOneToManyGrids">
<RelationshipTypeRule AppliesTo="SelectedEntity" RelationshipType="OneToMany" />
</DisplayRule>
</DisplayRules>-----------------------------------------------------------------------------------------------------------------------------
<EnableRule Id="Mscrm.AppendToPrimary">
<RecordPrivilegeRule AppliesTo="PrimaryEntity" PrivilegeType="AppendTo" />
</EnableRule>
<EnableRule Id="Mscrm.EntityFormIsEnabled">
<FormStateRule State="Disabled" InvertResult="true" />
</EnableRule><EnableRule Id="Mscrm.AddExistingRecordFromSubGridAssociated.Enabled.Custom">
<CustomRule Default="false" FunctionName="EnableNewButton" Library="/CustomToolsButton/EnableButton.js">
<CrmParameter Value="PrimaryEntityTypeName" />
</CustomRule></EnableRule>
--------------------------------------------------------------------------------------------------
I have a EnableButton.js file under CustomToolsButton directory, the following is the function:
function EnableNewButton(PrimaryEntityTypeCode) {
alert("heee");
return false;
}I want to know the funtion EnableNewButton is called, but it can't pop up after I click the other related entity.
and the New Existing button is still be enabled.
I don't know what's wrong with it, it's so weird.
Hope someone help me,
Thanks in advance.
Saturday, September 28, 2013 2:27 PM
Answers
-
Hi Mike,
I think you want to hide the Add existing button for Contact entity. The Add Existing button is available on Contacts sub grid. You are performing operation on Orders sub grid.
Here are the steps- Create a new solution Add contact entity and export it.
- Open the customizations file and look for "<RibbonDiffXml>" tag.
- Replace the <CustomActions /> with<CustomActions>
<HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingAssoc" HideActionId="Mscrm.SubGrid.contact.AddExistingAssoc.HideAction" />
<HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingStandard" HideActionId="Mscrm.SubGrid.contact.AddExistingStandard.HideAction" />
</CustomActions>Refer below blog for more info.
http://mscrmshop.blogspot.in/2011/07/step-by-step-hiding-add-existing-button.html
Hope this helps!
- Marked as answer by Michael Wu (MBSG) Saturday, October 19, 2013 11:22 AM
Sunday, September 29, 2013 7:50 AM
All replies
-
Hi Michael,
Firstly, in order to customize System Ribbon Buttons (OOB Ribbon Buttons), you have to override them by hiding the existing button and replacing them with a custom button with the same definition. I am not sure if you have done this or not.
Check the below link for step by step walkthrough.
http://crmdm.blogspot.in/2012/01/how-to-override-system-ribbon-button-in.html
So, you have to hide the existing system button by using the HideCustomAction if not already done.
Then, you specify the definition for your new button that overrides the System Button using the CustomAction. This you have done already, but I do not see the Sequence property of the CustomAction specified in your code fragment. In CommandUIDefintion, specify a ID for the button which is different than the original System Button ID.
You can use some tools for achieving the same. Check the below link to learn more about easily customizing buttons using Ribbon Workbench.
http://www.madronasg.com/blog/how-use-dynamics-crm-ribbon-workbench-customize-button-behavior
Saturday, September 28, 2013 5:24 PM -
Um. I have done what you said, but it didn't work,
then I clean all the content under the CustomActions tag. I try to hide the Add Existing button by using HideCustomAction.
As:
<CustomActions>
<HideCustomAction HideActionId="Mscrm.SubGrid.salesorder.AddExistingStandard.HideCustomAction" Location="Mscrm.SubGrid.salesorder.AddExistingStandard"/>
</CustomActions>
after I imported the solution, I click the related entity, the 'Add Existing' button still be display.
I suppose that the HideCustomAction is useless.
I'm frustrated now. Hope someone help me.
Sunday, September 29, 2013 7:04 AM -
Hi Mike,
I think you want to hide the Add existing button for Contact entity. The Add Existing button is available on Contacts sub grid. You are performing operation on Orders sub grid.
Here are the steps- Create a new solution Add contact entity and export it.
- Open the customizations file and look for "<RibbonDiffXml>" tag.
- Replace the <CustomActions /> with<CustomActions>
<HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingAssoc" HideActionId="Mscrm.SubGrid.contact.AddExistingAssoc.HideAction" />
<HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingStandard" HideActionId="Mscrm.SubGrid.contact.AddExistingStandard.HideAction" />
</CustomActions>Refer below blog for more info.
http://mscrmshop.blogspot.in/2011/07/step-by-step-hiding-add-existing-button.html
Hope this helps!
- Marked as answer by Michael Wu (MBSG) Saturday, October 19, 2013 11:22 AM
Sunday, September 29, 2013 7:50 AM -
I recommend you take a look at using the Ribbon Workbench. This will make ribbon customizations much easier.
http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx
Please feel free to contact me via any of the following methods:
Sunday, September 29, 2013 8:08 PM -
Hah..Yes, You are right, KalimK, thanks! thanks everyone all the same! I have got it.
As you know, I want to hide these two buttons when I click contact entity on left navigation, but I still want to show these two button when I open another entity
related with contact entity.
I know I could use display rules to achieve it. but which kind of display rules could I use for it?
I have try to use EntityRule like this:
<DisplayRules >
<DisplayRule Id="Mscrm.SubGrid.contact.AddNewStandard.DisplayRules">
<EntityRule AppliesTo="PrimaryEntity" Context="SubGridAssociated" EntityName="salesorder" />
</DisplayRule>
</DisplayRules>But it didn't work.
I suppose that I should make a mistake, I was wondering if I choose a wrong rule or make a wrong with the rule?
Thanks in advance!
Monday, September 30, 2013 2:35 AM -
And how to do this only for contact subgrid when contact subgrid is on my custom entity form ?Monday, February 3, 2014 1:34 PM
-
Hi,
If you want to restrict to a specific entity - then you can use the EntityRule and set AppliedTo=Primary Entity and the Entity=contact.
Hope this helps,
Scott
Scott Durow
Blog www.develop1.netFollow Me
Rockstar365
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Proposed as answer by Scott Durow (MVP)MVP, Editor Monday, February 10, 2014 11:29 AM
Monday, February 10, 2014 11:29 AMAnswerer