zoukankan      html  css  js  c++  java
  • MS CRM 2011 如何向自定义Ribbon按钮传递参数

    原创地址:http://www.cnblogs.com/jfzhu/archive/2012/09/27/2706005.html

    转载请注明出处

    首先介绍一下,如果你想查看CRM默认的(标准的)Ribbon定义,可以在sdk\resources\exportedribbonxml文件夹中找到对应Entity的xml文件。如果你想查看某个自定义Entity的ribbon定义,或者你已经对某个Entity进行了修改,可以将改Entity的ribbon定义导出到xml文件中,具体的操作可以参见sdk 中Export Ribbon Definitions这一章节。

    在本文中,我们对客户(account)的ribbon进行修改。假如我们是一家投资公司,我们要为Connect按钮增加一个子选项To Investment Partner(默认的子选项有两个To Me和To Another)。

    image

    我们要在客户的表单上以及grid中对connect ribbon按钮进行修改,然后我们传递几个参数给我们connect按钮的新子选项,包括accountid,object type code,object type name。

    首先我们要做的是,新建一个solution,并将account entity添加进来,注意不要添加其他”required components”。接下来我们新建一个Jscript web resource,我们命名它为AccountLibrary.js。js的代码我们一会再添加,现在先保存好solution,并导出来,解压缩后,我们对customizations.xml文件进行修改。

    <RibbonDiffXml>
      <CustomActions>
        <CustomAction Id="mycompany.account.form.ConnectToInvestmentPartner.CustomAction" Location="Mscrm.Form.account.AddConnection.Controls._children" Sequence="42">
          <CommandUIDefinition>
            <Button Id="mycompany.account.form.ConnectToInvestmentPartner.Button" Command="mycompany.account.form.ConnectToInvestmentPartner.Command" LabelText="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipTitle="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipDescription="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.ToolTip" />
          </CommandUIDefinition>
        </CustomAction>
        <CustomAction Id="mycompany.account.grid.ConnectToInvestmentPartner.CustomAction" Location="Mscrm.HomepageGrid.account.AddConnection.Controls._children" Sequence="46">
          <CommandUIDefinition>
            <Button Id="mycompany.account.homepagegrid.ConnectToInvestmentPartner.Button" Command="mycompany.account.grid.ConnectToInvestmentPartner.Command" LabelText="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipTitle="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipDescription="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.ToolTip" />
          </CommandUIDefinition>
        </CustomAction>
        <CustomAction Id="mycompany.account.subgrid.ConnectToInvestmentPartner.CustomAction" Location="Mscrm.SubGrid.account.AddConnection.Controls._children" Sequence="21">
          <CommandUIDefinition>
            <Button Id="mycompany.account.subgrid.ConnectToInvestmentPartner.Button" Command="mycompany.account.grid.ConnectToInvestmentPartner.Command" LabelText="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipTitle="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.LabelText" ToolTipDescription="$LocLabels:mycompany.account.form.ConnectToInvestmentPartner.ToolTip" />
          </CommandUIDefinition>
        </CustomAction>
      </CustomActions>
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="mycompany.account.form.ConnectToInvestmentPartner.Command">
          <EnableRules>
            <EnableRule Id="Mscrm.Enabled" />
          </EnableRules>
          <DisplayRules />
          <Actions>
            <JavaScriptFunction Library="$webresource:new_AccountLibrary.js" FunctionName="AccountLibrary.AddConnectionToInvestmentPartner">
              <CrmParameter Value="FirstPrimaryItemId" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <CrmParameter Value="PrimaryEntityTypeName" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="mycompany.account.grid.ConnectToInvestmentPartner.Command">
          <EnableRules>
            <EnableRule Id="Mscrm.Enabled" />
          </EnableRules>
          <DisplayRules />
          <Actions>
            <JavaScriptFunction Library="$webresource:new_AccountLibrary.js" FunctionName="AccountLibrary.AddConnectionToInvestmentPartner">
              <CrmParameter Value="FirstSelectedItemId" />
              <CrmParameter Value="SelectedEntityTypeCode" />
              <CrmParameter Value="SelectedEntityTypeName" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules />
        <EnableRules />
      </RuleDefinitions>
      <LocLabels>
        <LocLabel Id="mycompany.account.form.ConnectToInvestmentPartner.LabelText">
          <Titles>
            <Title languagecode="1033" description="To Investment Partner" />
            <Title languagecode="2052" description="投资伙伴" />
          </Titles>
        </LocLabel>
        <LocLabel Id="mycompany.account.form.ConnectToInvestmentPartner.ToolTip">
          <Titles>
            <Title languagecode="1033" description="To Investment Partner" />
            <Title languagecode="2052" description="投资伙伴" />
          </Titles>
        </LocLabel>
      </LocLabels>
    </RibbonDiffXml>

    我们在三处对account进行了修改:Form,HomepageGrid和SubGrid。

    在Form上,我们使用的是以下几个参数:

    <CrmParameter Value="FirstPrimaryItemId" />
    <CrmParameter Value="PrimaryEntityTypeCode" />
    <CrmParameter Value="PrimaryEntityTypeName" />

    在HomepageGrid和SubGrid,我们使用的是以下几个参数:

    <CrmParameter Value="FirstSelectedItemId" />
    <CrmParameter Value="SelectedEntityTypeCode" />
    <CrmParameter Value="SelectedEntityTypeName" />

    如果想查看完整的参数列表,可以查找SDK中“<CrmParameter> (RibbonDiffXml)”一节。再来看一下Jscript代码,把这段代码拷贝到AccountLibrary.js web resource中去。

    if (typeof (AccountLibrary) == "undefined") {
        AccountLibrary = { __namespace: true };
    }
    
    
    AccountLibrary = {
        Name: "AccountLibrary",
        AddConnectionToInvestmentPartner: function (accountid, objecttypecode, objecttypename) {
            try {
                alert("account id = " + accountid);
                alert("objecttypecode = " + objecttypecode);
                alert("objecttypename = " + objecttypename);
            }
            catch (e) {
                alert(AccountLibrary.Name + " AddConnectionToInvestmentPartner Error: " + e.Message);
            }
        }
    } 

    来看一下最后的效果:

    image

    image

    image

  • 相关阅读:
    docker-machine create ,,,
    docker run with zabbix3.0
    mysql 官网
    取模性质
    欧涛最短路【记录最短路径】
    P4568 飞行路线【分层图最短路】
    CCF201403 无线网络【限制型最短路】
    POJ2449 【第k短路/A*】
    Feeding Time 【bfs求最大连通块】
    printf特殊用法
  • 原文地址:https://www.cnblogs.com/jfzhu/p/2706005.html
Copyright © 2011-2022 走看看