我试图通过功能区按钮执行视图中所选记录的工作流程。我必须使用“传统”服务,为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对象的示例,因此仅供参考。
谢谢!