从CRM触发多个实体的插件

时间:2016-10-19 21:37:03

标签: javascript c# dynamics-crm

我已经看到了从功能区按钮执行插件的解决方案。例如: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#代码中过滤)。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:1)

创建操作时,请为实体指定“无”。这使得行动具有全球性。全局操作不需要传递实体引用。所以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的有效性。)

答案 1 :(得分:0)

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