[英]How to Execute FetchXML in CRM 2011 using a CRM 2011 webservice and JavaScript?
[英]Execute workflow from JavaScript in CRM 2011
我正在嘗試通過功能區按鈕為視圖中選擇的記錄執行工作流程。 我有一個使用“遺留”服務實現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對象的示例,因此它只是最好的猜測。
謝謝!
在CRM sdk文件夾\\ samplecode \\ cs \\ client \\ soaplogger中有一個名為SOAPLogger的應用程序,它在javascript中為特定操作生成請求。
在下面,您可以找到“ExecuteWorkflow”的http請求(只需更改EntityIdValue
和WorkflowIdValue
的值)。
<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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.