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.

Friday, June 1, 2012

Remove item from picklist programatically in CRM 2011 with javascript

In Dynamics CRM 2011, I have a pick-list for my Opportunities with the follwing options, which influences my Sales Pipeline:
1 - Prospect
2 - Proposal
3 - Negotiation

What i had to do is to filter the picklist so that only some of the options to be available, not all of them in the same time, ensuring that the user can't jump stages (jumping from 1 to 3), and that the user can't go backwards (from 2 to 1, from 3 to 2 or 1).

The code is:

// Get value of Pipeline Phase set by user
if (Xrm.Page.getAttribute("new_salesstagecode").getSelectedOption() != null)
{var val_salesstagecode = Xrm.Page.getAttribute("new_salesstagecode").getSelectedOption().value;}
else {var val_salesstagecode = null;}

// Filter Pipeline Phase picklist to avoid users jumping stages
if (val_salesstagecode == 1)
{ Xrm.Page.getControl("new_salesstagecode").removeOption(3); }

else if (val_salesstagecode == 2)
{ Xrm.Page.getControl("new_salesstagecode").removeOption(1); }

else if (val_salesstagecode == 3)
{
Xrm.Page.getControl("new_salesstagecode").removeOption(1);
Xrm.Page.getControl("new_salesstagecode").removeOption(2);
}