7

我是 crm 2011 的新手。我找到了有关如何向功能区添加新按钮的文档。以及如何对按钮进行分组。但我需要功能区中的下拉菜单按钮。我怎样才能做到这一点?我没有找到任何有关此的信息。

谢谢!

4

1 回答 1

13

这应该让你开始。如果您只需要一个静态菜单,您可以将标签放在 Flyout Control 中并从那里构建菜单。

<FlyoutAnchor Id="Sample.account.form.FlyoutAnchor.Static"
              Sequence="10"
              Command="Mscrm.Enabled"
              Image16by16="/_imgs/placeholders/ribbon_placeholder_16.png"
              Image32by32="/_imgs/ribbon/newrecord32.png"
              LabelText="Sample Flyout"
              Alt="Sample Flyout"            
              TemplateAlias="isv">
  <Menu Id="Sample.account.form.Menu">
    <MenuSection Id="Sample.account.form.MenuSection" 
                 Title="Menu Section Title" 
                 Sequence="15">
      <Controls Id="Sample.account.form.MenuSection.Controls">
        <Button Id="Sample.account.form.Controls.Button.FirstButton"
                Command="Sample.ButtonCommand.Command"
                LabelText="First Button"
                ToolTipTitle="First Button"
                ToolTipDescription="The first button"
                TemplateAlias="isv"
                Sequence="20"/>
      </Controls>
    </MenuSection>
  </Menu>
</FlyoutAnchor>

如果要动态生成菜单,则可以使用此弹出控件。请注意添加的填充属性。然后你必须通过javascript构建菜单。

<FlyoutAnchor Id="Sample.account.form.FlyoutAnchor.Dynamic"
              Sequence="10"
              Command="Mscrm.Enabled"
              Image16by16="/_imgs/placeholders/ribbon_placeholder_16.png"
              Image32by32="/_imgs/ribbon/newrecord32.png"
              LabelText="Sample Flyout"
              Alt="Sample Flyout"
              PopulateDynamically="true"
              PopulateQueryCommand="Sample.PopulateDynamicMenu"
              TemplateAlias="isv" />

我创建了两个访问 javascript 函数的命令。DynamicMenu 构建菜单,Search 用于确定按下了哪个按钮控件。请注意,这两个都传递了 CommandProperties 参数,这对 javascript 很重要。

<CommandDefinition Id="Sample.PopulateDynamicMenu">
      <EnableRules>
        <EnableRule Id="Mscrm.Enabled" />
      </EnableRules>
      <DisplayRules />
      <Actions>
        <JavaScriptFunction FunctionName="DynamicMenu"
                            Library="$webresource:a_JavaScript_File">
          <CrmParameter Value="CommandProperties" />
        </JavaScriptFunction>
      </Actions>
</CommandDefinition>
<CommandDefinition Id="Sample.SearchCommand">
      <EnableRules />
      <DisplayRules />
      <Actions>
        <JavaScriptFunction FunctionName="Search" 
                            Library="$webresource:a_JavaScript_File">
          <CrmParameter Value="CommandProperties" />
        </JavaScriptFunction>
      </Actions>
</CommandDefinition>

以下是javascript函数:

function DynamicMenu(CommandProperties) {
    ///<summary>Dynamically generate menu items based on context</summary>
    /// <param name="CommandProperties">
    ///    Command properties crm parameter sent from the ribbon.  object used to inject the Menu XML
    /// </param>

    var menuXml = '<Menu Id="Sample.DynamicMenu">' +
                    '<MenuSection Id="Sample.Dynamic.MenuSection" Sequence="10">' +
                        '<Controls Id="Sample.Dynamic.Controls">' +
                            '<Button Id="Sample.account.form.Controls.Button.FirstButton"' +
                                    ' Command="Sample.SearchCommand"' +
                                    ' LabelText="First Button"' +
                                    ' ToolTipTitle="First Button"' +
                                    ' ToolTipDescription="The first button"' +
                                    ' TemplateAlias="isv"' +
                                    ' Sequence="20" />' +                                  
                        '</Controls>' +
                    '</MenuSection>' +
                '</Menu>';


    CommandProperties.PopulationXML = menuXml;
}

function Search(CommandProperties) {
    ///<summary>Determines which control was pressed</summary>
    /// <param name="CommandProperties">
    ///    Command properties crm parameter sent from the ribbon.  object used to read which dynamically generated
    ///    button is selected.
    /// </param>

    var controlId = CommandProperties.SourceControlId;
    switch (controlId) {
        case 'Sample.account.form.Controls.Button.FirstButton':
            alert(controlId + ' was pressed!');
            break;        
        default:
            alert('unknown');
    }
}
于 2011-04-30T14:08:22.847 回答