Adding checkbox in MS CRM ribbon

Ever tried adding a checkbox in the CRM ribbon form? This post will be helpful for that requirement.

Requirement:

a)  Adding a checkbox in the contact entity in CRM form ribbon.

b)  An action will be triggered when the checkbox is checked in the ribbon form.

Prerequisites:

a) Solution needs to have the a javascript web resource

 i)  The name of the javascript web resource is sample_Trigger which will trigger when the checkbox is checked. Following is the function which you can write in the javascript file.

Function trigger()

{

       alert("Check box is checked");

}

 

Steps to achieve the requirement:

1)  Navigate to Settings- Solutions and click on new solution which will open a new window as shown in the below figure

     

 

2) Click on the save button and add the existing contact entity which will add the contact entity. If you want to import the solution back into the same organization then you can include missing required components. Other component which you should add for this solution is a javascript file of name ‘sample_Trigger’ as shown in the below figure.

 

                              

 

3) After adding the required entities into the solution export the solution to make modifications as per the requirement. This will open a compressed file which includes three xml files Content_Types.xml, customizations.xml, solution.xml and a webresources folder.

4) Our aim is to do some custom action in the form ribbon. In order to achieve that requirement we need to modify the customizations.xml file. Modify the ribbondiffxml tab by replacing it with the following code.

<RibbonDiffXml>

        <CustomActions>

          <CustomAction Id="MyISV.contact.grid.trigger.CustomAction" Location="Mscrm.HomepageGrid.contact.MainTab.Collaborate.Controls._children" Sequence="41">

            <CommandUIDefinition>

              <CheckBox Command="MyISV.contact.form.trigger.Command" Id="MyISV.contact.form.trigger.Button" LabelText="$LocLabels:MyISV.contact.trigger.LabelText" TemplateAlias="o2" ToolTipDescription="$LocLabels:MyISV.contact.trigger.ToolTip" ToolTipTitle="$LocLabels:MyISV.contact.trigger.LabelText" />

            </CommandUIDefinition>

          </CustomAction>

          <CustomAction Id="MyISV.contact.form.trigger.CustomAction" Location="Mscrm.Form.contact.MainTab.Collaborate.Controls._children" Sequence="33">

            <CommandUIDefinition>

              <CheckBox Command="MyISV.contact.form.trigger.Command" Id="MyISV.contact.form.trigger.Button" LabelText="$LocLabels:MyISV.contact.trigger.LabelText" TemplateAlias="o2" ToolTipDescription="$LocLabels:MyISV.contact.trigger.ToolTip" ToolTipTitle="$LocLabels:MyISV.contact.trigger.LabelText" />

            </CommandUIDefinition>

          </CustomAction>

        </CustomActions>

        <Templates>

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

        </Templates>

        <CommandDefinitions>

          <CommandDefinition Id="MyISV.contact.grid.trigger.Command">

            <EnableRules>

              <EnableRule Id="MyISV.contact.WebClient.EnableRule" />

              <EnableRule Id="MyISV.contact.grid.OneSelected.EnableRule" />

            </EnableRules>

            <DisplayRules>

              <DisplayRule Id="MyISV.contact.WebClient.DisplayRule" />

            </DisplayRules>

            <Actions>

              <JavaScriptFunction Library="$webresource:sample_Trigger" FunctionName="trigger" />

            </Actions>

          </CommandDefinition>

          <CommandDefinition Id="MyISV.contact.form.trigger.Command">

            <EnableRules>

              <EnableRule Id="MyISV.contact.WebClient.EnableRule" />

              <EnableRule Id="MyISV.contact.form.NotNew.EnableRule" />

            </EnableRules>

            <DisplayRules>

              <DisplayRule Id="MyISV.contact.form.FormStateNotNew.DisplayRule" />

              <DisplayRule Id="MyISV.contact.WebClient.DisplayRule" />

            </DisplayRules>

            <Actions>

              <JavaScriptFunction Library="$webresource:sample_Trigger" FunctionName="trigger" />

            </Actions>

          </CommandDefinition>

        </CommandDefinitions>

        <RuleDefinitions>

          <TabDisplayRules />

          <DisplayRules>

            <DisplayRule Id="MyISV.contact.form.FormStateNotNew.DisplayRule">

              <FormStateRule State="Create" InvertResult="true" />

            </DisplayRule>

            <DisplayRule Id="MyISV.contact.WebClient.DisplayRule">

              <CrmClientTypeRule Type="Web" />

            </DisplayRule>

          </DisplayRules>

          <EnableRules>

            <EnableRule Id="MyISV.contact.WebClient.EnableRule">

              <CrmClientTypeRule Type="Web" />

            </EnableRule>

            <EnableRule Id="MyISV.contact.form.NotNew.EnableRule">

              <FormStateRule State="Create" InvertResult="true" />

            </EnableRule>

            <EnableRule Id="MyISV.contact.grid.OneSelected.EnableRule">

              <SelectionCountRule AppliesTo="SelectedEntity" Maximum="1" Minimum="1" />

            </EnableRule>

          </EnableRules>

        </RuleDefinitions>

        <LocLabels>

          <LocLabel Id="MyISV.contact.trigger.LabelText">

            <Titles>

              <Title languagecode="1033" description="Trigger an action" />

            </Titles>

          </LocLabel>

          <LocLabel Id="MyISV.contact.trigger.ToolTip">

            <Titles>

              <Title languagecode="1033" description="Trigger an action" />

            </Titles>

          </LocLabel>

        </LocLabels>

      </RibbonDiffXml>

5) After making modifications in the customizations.xml file compress the "Customizations.xml", "Solutions.xml", "Content-Types.xml" and the Webresources folder which includes the javascript file sample_trigger. Import the compressed zip file back into the CRM organization and publish all the customizations.

6) This will create a checkbox in the form ribbon and trigger an action when the checkbox is checked.