Wednesday, June 13, 2012

How to create dropdown menu in ribbon Crm 2011

To create a dropdown menu in ribbon for crm 2011 you have to use the FlyoutAnchor element.

To add it in the solution you have to first export the solution from CRM 2011 and open for editing  the Configuration.xml file.

Steps to build the element in the configuration file:

1)In the CustomActions tag of the RibbonDiffXml you have to add the code:
 <CustomActions>
          <CustomAction Id="Status" Location="Mscrm.Form.new_area.MainTab.Save.Controls._children">
            <CommandUIDefinition>
              <FlyoutAnchor Id="ISV.AreaStatusFlyout" Sequence="100" Command="Mscrm.Enabled" Image16by16="/_imgs/placeholders/ribbon_placeholder_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" LabelText="Status" Alt="Status" PopulateOnlyOnce="false" PopulateDynamically="false" TemplateAlias="isv">
                <Menu Id="ISV.DynamicAreaStatus">
                  <MenuSection Id="ISV.AreaStatus.MenuSection\" Sequence="101">
                    <Controls Id="ISV.AreaStatus.Controls">
                      <Button Id="ISV.AreaStatus.Button1" Command="ISV.AreaStatus.Open" Sequence="102" LabelText="Open" Alt="Open" />
                      <Button Id="ISV.AreaStatus.Button2" Command="ISV.AreaStatus.Active" Sequence="103" LabelText="Active" Alt="Active" />
                      <Button Id="ISV.AreaStatus.Button3" Command="ISV.AreaStatus.Closed" Sequence="104" LabelText="Closed" Alt="Closed" />
                    </Controls>
                  </MenuSection>
                </Menu>
              </FlyoutAnchor>
            </CommandUIDefinition>
          </CustomAction>


2) In the CommandDefinitions section of the RibbonDiffXml you have to add the commands for each button inserted in FlyoutAnchor.

 <CommandDefinitions>
          <CommandDefinition Id="ISV.AreaStatus.Open">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="AreaStatus_Open" Library="$webresource:new_jsFile.js">
                <CrmParameter Value="FirstPrimaryItemId" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="ISV.AreaStatus.Active">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="AreaStatus_Activ" Library="$webresource:new_
jsFile.js">
                <CrmParameter Value="FirstPrimaryItemId" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>

          <CommandDefinition Id="ISV.AreaStatus.Closed">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="Close" Library="$webresource:new_
jsFile.js">
                <CrmParameter Value="FirstPrimaryItemId" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>


For each button i assigned a function from the javascript file called: new_jsFile.js.

Save the Customizations.xml File and upload it to the CRM.

No comments:

Post a Comment