2012-07-18 82 views
5

我試圖通過功能區按鈕執行視圖中所選記錄的工作流程。我必須使用「傳統」服務,爲CRM 4兼容性工作的例子:從CRM 2011中的JavaScript執行工作流程

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對象的示例,因此僅供參考。

謝謝!

回答

7

在CRM sdk文件夾\ samplecode \ cs \ client \ soaplogger中有一個名爲SOAPLogger的應用程序,它在javascript中爲特定操作生成請求。

下面,你可以找到「ExecuteWorkflow」(只是改變了EntityIdValueWorkflowIdValue值)的HTTP請求。

<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建設是corect,所以嘗試改變soapEnvelope

相關問題