触发插件从CRM的多个实体

本文关键字:实体 CRM 插件 | 更新日期: 2023-09-27 18:13:57

我已经看到了从ribbon按钮执行插件的解决方案。例如:https://www.greenbeacon.com/insights/trigger-plugin-from-ribbon-button-using-custom-actions-in-dynamics-crm-2013/。然而,我想做的是启用一个插件的执行,不涉及一个特定的实体。在该解决方案的JavaScript中,它包含如下内容:

requestXML += "            <b:value i:type="a:EntityReference">";
requestXML += "              <a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>";

但是我不想把它限制为一个id。我希望有人在一个帐户视图,并单击一个按钮执行批处理过程,使用插件,对所有帐户(在c#代码中过滤)。有办法做到这一点吗?

触发插件从CRM的多个实体

创建动作时,为Entity指定None。这使得行动具有全局性。全局操作不需要传递实体引用。所以JS看起来像这样:

function ExecuteAction(requestName, refreshPage, stringParameter) {
    // Creating the request XML for calling the Action
    var requestXML = ""
    requestXML += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">';
    requestXML += '  <s:Body>';
    requestXML += '    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">';
    requestXML += '      <request xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">';
    requestXML += '        <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">';
    requestXML += '          <a:KeyValuePairOfstringanyType>';
    requestXML += '            <b:key>Data</b:key>';
    requestXML += '            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">' + stringParameter + '</b:value>';
    requestXML += '          </a:KeyValuePairOfstringanyType>';
    requestXML += '        </a:Parameters>';
    requestXML += '        <a:RequestId i:nil="true " />';
    requestXML += '        <a:RequestName>' + requestName + '</a:RequestName>';
    requestXML += '      </request>';
    requestXML += '    </Execute>';
    requestXML += '  </s:Body>';
    requestXML += '</s:Envelope>';
    var req = new XMLHttpRequest();
    req.open("POST", GetServiceUrl(), false)
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.send(requestXML);
    //refresh the page if the request was successful.
    if (req.status == 200) {
        if (refreshPage) {
            RefreshForm()
        }
    } else {
        Xrm.Utility.alertDialog(req.statusText + "n" + req.responseXML.getElementsByTagName("faultstring")[0].textContent);
    }
}

(注意,当我从博客文章中复制代码时,我必须翻转所有的引号字符并重新格式化代码。我可能遗漏了一些东西,所以您需要再次检查XML的有效性。)

在为这样的插件注册步骤时,不要选择Entity而是Message,然后在从Javascript调用它时不需要传递任何输入参数给插件