2012-07-18 20 views
5

Tôi đang cố gắng thực thi luồng công việc cho các bản ghi được chọn trong chế độ xem, qua nút ruy-băng. Tôi có một ví dụ làm việc sử dụng dịch vụ 'di sản' CRM 4 tương thích cho:Thực hiện quy trình làm việc từ JavaScript trong CRM 2011

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); 
} 

Tuy nhiên, tôi muốn viết này sử dụng dịch vụ CRM 2011 để tăng khả năng bảo trì cho các phiên bản trong tương lai. Đây là những gì tôi đã cố gắng cho đến nay, nhưng điều này không hoạt động - mã trả về của cuộc gọi là HTTP 500 (Lỗi Máy chủ Nội bộ).

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); 
} 

Có ai biết điều gì sai với tập lệnh thứ hai không? Tôi đã thử Googling này là tốt nhất tôi có thể, nhưng mỗi ví dụ tôi tìm thấy mà tuyên bố được cho CRM 2011 là trong thực tế chỉ cần sử dụng các dịch vụ tương thích CRM 4 (như trong ví dụ đầu tiên). Tôi đã dựa trên ví dụ thứ hai từ một mẫu trong CRM 2011 SDK, mặc dù điều này không bao gồm một ví dụ về đối tượng ExecuteWorkflowRequest vì vậy nó chỉ đoán tốt nhất.

Cảm ơn!

Trả lời

7

Có một ứng dụng có tên SOAPLogger trong thư mục sdk CRM \ samplecode \ cs \ client \ soaplogger tạo yêu cầu trong javascript cho các hành động cụ thể.

Dưới đây, bạn có thể tìm thấy yêu cầu http cho "ExecuteWorkflow" (chỉ cần thay đổi giá trị cho 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> 

Việc xây dựng XMLHttpRequest là corect, vì vậy hãy thử thay đổi soapEnvelope.

Các vấn đề liên quan