5

我正在尝试通过功能区按钮为视图中选择的记录执行工作流。我有一个使用“旧”服务来实现 CRM 4 兼容性的工作示例:

function invokeWorkflow(workflowId, entityId) {
    var request =
        '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        '               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '               xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
           GenerateAuthenticationHeader() +
        '  <soap:Body>' +
        '    <Execute xmlns="http://schemas.microsoft.com/crm/2007/WebServices">' +
        '      <Request xsi:type="ExecuteWorkflowRequest">' +
        '        <EntityId>' + entityId + '</EntityId>' +
        '        <WorkflowId>' + workflowId + '</WorkflowId>' +
        '      </Request>' +
        '    </Execute>' +
        '  </soap:Body>' +
        '</soap:Envelope>';

    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/MSCRMservices/2007/crmservice.asmx', false);

    xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');

    xhr.send(request);
}

但是,我想使用 CRM 2011 服务来编写这篇文章,以提高未来版本的可维护性。这是我到目前为止尝试过的,但这不起作用 - 调用的返回码是 HTTP 500(内部服务器错误)。

function invokeWorkflow(workflowId, entityId) {
    var request =
        '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        '               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '               xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
        '  <soap:Body>' +
        '    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">' +
        '      <Request xsi:type="ExecuteWorkflowRequest">' +
        '        <EntityId>' + entityId + '</EntityId>' +
        '        <WorkflowId>' + workflowId + '</WorkflowId>' +
        '      </Request>' +
        '    </Execute>' +
        '  </soap:Body>' +
        '</soap:Envelope>';

    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/XRMServices/2011/Organization.svc/web', true);

    xhr.setRequestHeader('Accept', 'application/xml, text/xml, */*');
    xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute');

    xhr.onreadystatechange = function () { alert(xhr.status); };
    xhr.send(request);
}

有谁知道第二个脚本有什么问题?我已经尽我所能尝试谷歌搜索,但我发现的每个声称适用于 CRM 2011 的示例实际上只是使用 CRM 4 兼容性服务(如第一个示例中所示)。我基于 CRM 2011 SDK 中的示例中的第二个示例,虽然这不包括 ExecuteWorkflowRequest 对象的示例,所以它只是最好的猜测。

谢谢!

4

1 回答 1

7

在 CRM sdk 文件夹 \samplecode\cs\client\soaplogger 中有一个名为SOAPLogger的应用程序,它在 javascript 中为特定操作生成请求。

下面,您可以找到“ExecuteWorkflow”的 http 请求(只需更改 和 的值EntityIdValueWorkflowIdValue

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <request i:type="b:ExecuteWorkflowRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
        <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <c:key>EntityId</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">EntityIdValue</c:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <c:key>WorkflowId</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">WorkflowIdValue</c:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil="true" />
        <a:RequestName>ExecuteWorkflow</a:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>

的构造XMLHttpRequest是正确的,因此请尝试更改soapEnvelope.

于 2012-07-20T09:37:44.363 回答