Dynamics CRM 2011 · Ribbon

CRM 2011: Hide Add New Button on Subgrid Tab using FormEntityContextRule

The code below hides the ‘Add New’ button for entity new_x (one) on entity new_y (many).

Please note that this is valid for one-to-many relationship only.

Below is a copy of the add new command definition with an added display rule (highlighted).

<CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
	<EnableRules>
	  <EnableRule Id="Mscrm.AppendToPrimary" />
	  <EnableRule Id="Mscrm.EntityFormIsEnabled" />
	</EnableRules>
	<DisplayRules>
	  <DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
	  <DisplayRule Id="Mscrm.AppendToPrimary" />
	  <DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
	  <DisplayRule Id="Mscrm.AppendSelected" />
	  <DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
	  <DisplayRule Id="New.AddNewXSubgridRule" />
	</DisplayRules>
	<Actions>
	  <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
		<CrmParameter Value="SelectedEntityTypeCode" />
		<CrmParameter Value="PrimaryEntityTypeCode" />
		<CrmParameter Value="FirstPrimaryItemId" />
		<CrmParameter Value="PrimaryControl" />
	  </JavaScriptFunction>
	</Actions>
</CommandDefinition>

Below is the display rule to hide the add new button for new_x subgrid on new_y form. Notice the InvertResult="true".

<DisplayRules>
	<DisplayRule Id="New.AddNewXSubgridRule">
		<FormEntityContextRule EntityName="new_y" Default="true" InvertResult="true" />
	</DisplayRule>
</DisplayRules>

Cheers – Sy

Advertisements

5 thoughts on “CRM 2011: Hide Add New Button on Subgrid Tab using FormEntityContextRule

  1. Hi,

    I wasn’t able to get this to work. I want to hide the “Add New” button for contacts on the account form. I tried customizing the application ribbon for the “contact” entity and I added a FormEntityContextRule to only hide the “Add New” button for contacts if the parent entity is “account”. My rule is as follows:

    If I open an account and click on “Contacts”, the ‘Add New Button’ is hidden (as expected). If I now open up a Contact and then click on “Sub Contacts”, the ‘Add New’ button is hidden (not the desired result). I only want to hide the ‘Add New’ button when viewing contacts from within an Account.

    I hope you can help.
    Thanks

    1. Hi Roshan,

      I believe if you use the invert result, it should work. Although I did find similar problems when I was working on it. But you can try to add a FormEntityContextRule for ‘Contact’ entity and set invertresult to ‘false’ and see if it works.

      Let me know how you go.

      Sy

  2. Hi,

    I wanted to hide Add existing button for custom entity ‘File Note – new _llonote” on both Case and Contact entity.And, I wanted to hide Add New button for a custom entity ‘File Note – new _llonote” only for Case entity but not for Contact entity.
    I exported the File Note entity and add the following code but its not working for me.

    Please tell me where am I going wrong.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s