Friday, December 21, 2012

Hide 'Add New' button from ribbon

   Sometimes we need to remove Add New or Add Existing button from ribbon. In below image we can see the 1:N relationship between Order and Invoice. To remove Add New button from Invoice entity in Order record, we need to export Invoice entity.
Add New button in 1:N relation between Order and Invoice.


  • Open customizations.xml from exported solution.
  • Open invoiceribbon.xml from SDK(\SDK\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml) and select <CommandDefinition> with Id="Mscrm.AddNewRecordFromSubGridStandard".
  • Paste the copied <CommandDefinition> inside <CommandDefinitions> in customizations.xml.
  • Insert new <DisplayRuleinside <DisplayRulesto hide Add New button(can be seen in below tags with Id="Mscrm.HideAddNewForOrder").

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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="Mscrm.HideAddNewForOrder" />
    </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>

  • Define <DisplayRuleunder <DisplayRulesin <RuleDefinitionsas below.

1
2
3
<DisplayRule  Id="Mscrm.HideAddNewForOrder">
    <FormEntityContextRule EntityName="salesorder" Default="true" InvertResult="true" />
</DisplayRule>

  • This <DisplayRulewill hide Add New button ONLY from Invoice which is related with Order.

No comments:

Post a Comment