[英]Execute workflow from JavaScript in CRM 2011
I'm attempting to execute a workflow for records selected in a view, via a ribbon button. 我正在尝试通过功能区按钮为视图中选择的记录执行工作流程。 I have a working example using the 'legacy' services for CRM 4 compatibility: 我有一个使用“遗留”服务实现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);
}
However, I want to write this using CRM 2011 services to increase maintainability for future releases. 但是,我想使用CRM 2011服务来编写此内容,以提高未来版本的可维护性。 Here is what I've tried so far, but this does not work - the return code of the call is HTTP 500 (Internal Server Error). 这是我到目前为止所尝试的,但这不起作用 - 调用的返回码是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);
}
Does anyone know what's wrong with the second script? 有谁知道第二个脚本有什么问题? I've tried Googling this as best I can but every example I find which claims to be for CRM 2011 is in fact just using the CRM 4 compatibility services (as in the first example). 我尽可能地尝试使用谷歌搜索,但我发现哪些声称用于CRM 2011的每个例子实际上只是使用CRM 4兼容性服务(如第一个示例中所示)。 I've based the second example from a sample in the CRM 2011 SDK, although this doesn't include an example of the ExecuteWorkflowRequest object so it's best-guess only. 我基于CRM 2011 SDK中的示例中的第二个示例,尽管这不包括ExecuteWorkflowRequest对象的示例,因此它只是最好的猜测。
Thanks! 谢谢!
There is an application named SOAPLogger in the CRM sdk folder \\samplecode\\cs\\client\\soaplogger that generates requests in javascript for specific actions. 在CRM sdk文件夹\\ samplecode \\ cs \\ client \\ soaplogger中有一个名为SOAPLogger的应用程序,它在javascript中为特定操作生成请求。
Below, you can find the http request for "ExecuteWorkflow" (just change the value for EntityIdValue
and WorkflowIdValue
). 在下面,您可以找到“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>
The construction of XMLHttpRequest
is corect, so try changing the soapEnvelope
. XMLHttpRequest
的构造是corect,所以尝试更改soapEnvelope
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.