In CRM 2011, in a 1:N (One-to-Many) entity relationship one entity has a lookup attribute that allows an entity object to store a reference to another entity object for a particular entity.

For 1:N entity relationship Parent Entity will have Left Navigation link to see all the Children Entity records associated with it. User can add new child records from Parent form itself.

However if User have to remove the children records from Parent Entity, they have to open each child record form and set the Lookup up value as null or blank. This is some times lengthy processes especially if the number of records are high.

 

To address this problem I created CRM solution which will allow User to remove child records from Parent Entity form and they need not go to individual child record form.

Attached are Managed as well Un-managed solutions, depending upon your requirement you can import either of the solution.

This solution adds a Custom Ribbon button to the “Records” Group of Sub-Grid Ribbon (List Tools). 

 

Screenshot 1: “Remove” button is added to Sub-Grid Ribbon.

image

 

Screenshot 2: “Remove” button is enabled only when there is at least one selected record in Sub-Grid

image

 

Custom “Remove” Ribbon button is displayed only when following conditions are satisfied

1. Entity relationship is 1:n, Remove button is not enabled for n:n (many – to –many ) relationships

2. User has “Basic” privilege on “Write” access on Selected Sub-Grid entity.

3. User has “Basic” privilege on “Append” access on Selected Sub-Grid entity.

4. User has “Basic” privilege on “AppendTo” access on Primary Entity in Form.

 

Screenshot 3: Confirm Removal dialog box is shown which includes count of selected records by User in Sub-Grid

image

 

Screenshot 4: Process in Progress Message

image

 

Screenshot 5: Error message

image

 

If all records are successfully removed, then Conform dialog box will automatically close and refresh sub-grid.

 

For those who wanted to alter Ribbon customizations to make it available only for selected entities can alter Application Ribbon XML.

New Display Rules can be added.

Following is Ribbon Customization done in Application Ribbon

<RibbonDiffXml> 

    <CustomActions> 

      <CustomAction Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.CustomAction" Location="Mscrm.SubGrid.{!EntityLogicalName}.MainTab.Management.Controls._children" Sequence="41">

        <CommandUIDefinition> 

          <Button Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren" Command="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command" Sequence="130" ToolTipTitle="$LocLabels:makeer.SubGrid.EntityLogicalName.MainTab.Management.RemoveChildren.LabelText" LabelText="$LocLabels:makeer.SubGrid.EntityLogicalName.MainTab.Management.RemoveChildren.LabelText" ToolTipDescription="$LocLabels:makeer.SubGrid.EntityLogicalName.MainTab.Management.RemoveChildren.Description" TemplateAlias="isv" Image16by16="$webresource:makeer_/IMG/PNG/Remove_16x16.png" Image32by32="$webresource:makeer_/IMG/PNG/Remove_32x32.png" />

        </CommandUIDefinition> 

      </CustomAction> 

    </CustomActions> 

    <Templates> 

      <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>

    </Templates> 

    <CommandDefinitions> 

      <CommandDefinition Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command">

        <EnableRules> 

          <EnableRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.EnableRule.SelectionCountRule" />

        </EnableRules>

        <DisplayRules>

          <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.RelationshipTypeRule" />

          <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule" />

          <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule2" />

          <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule3" />

        </DisplayRules>

        <Actions>

          <JavaScriptFunction FunctionName="RemoveChildren" Library="$webresource:makeer_/Scripts/RemoveChildren.js">

            <CrmParameter Value="PrimaryEntityTypeName" />

            <CrmParameter Value="SelectedEntityTypeName" />

            <CrmParameter Value="SelectedControlSelectedItemIds" />

            <CrmParameter Value="SelectedControl" />

          </JavaScriptFunction>

        </Actions>

      </CommandDefinition>

    </CommandDefinitions>

    <RuleDefinitions>

      <TabDisplayRules />

      <DisplayRules>

        <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.RelationshipTypeRule">

          <RelationshipTypeRule RelationshipType="OneToMany" AppliesTo="SelectedEntity" />

        </DisplayRule>

        <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule">

          <EntityPrivilegeRule AppliesTo="PrimaryEntity" PrivilegeDepth="Basic" PrivilegeType="AppendTo" />

        </DisplayRule>

        <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule2">

          <EntityPrivilegeRule AppliesTo="SelectedEntity" PrivilegeDepth="Basic" PrivilegeType="Write" />

        </DisplayRule>

        <DisplayRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.DisplayRule.EntityPrivilegeRule3">

          <EntityPrivilegeRule AppliesTo="SelectedEntity" PrivilegeDepth="Basic" PrivilegeType="Append" />

        </DisplayRule>

      </DisplayRules>

      <EnableRules>

        <EnableRule Id="makeer.SubGrid.{!EntityLogicalName}.MainTab.Management.RemoveChildren.Command.EnableRule.SelectionCountRule">

          <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" Default="false" />

        </EnableRule>

      </EnableRules>

    </RuleDefinitions>

    <LocLabels>

      <LocLabel Id="makeer.SubGrid.EntityLogicalName.MainTab.Management.RemoveChildren.LabelText">

        <Titles>

          <Title languagecode="1033" description="Remove" />

        </Titles>

      </LocLabel>

      <LocLabel Id="makeer.SubGrid.EntityLogicalName.MainTab.Management.RemoveChildren.Description">

        <Titles>

          <Title languagecode="1033" description="Remove selected records.&#xD;&#xA;&#xD;&#xA;When you remove a record it still exists in the system." />

        </Titles>

      </LocLabel>

    </LocLabels>

  </RibbonDiffXml>

 

Last edited Mar 3, 2012 at 6:14 PM by makarand_keer, version 4