我尝试在表单加载时从我的javascript库运行工作流程。 但是当我发送请求时,我收到以下错误消息:
'POST http://theDestinationCRM/XRMServices/2011/Organization.svc/web 500(内部服务器错误)'
在工作流程的活动日志中,我看到它未启动。
我需要使用参数(testinput)触发工作流程,我需要接收工作流程/输出的答案。 worklow被定义为具有输入和输出的自定义actioin。
function RunWorkflow() {
var _return = window.confirm('Are you want to execute workflow.');
if (_return) {
var url = Xrm.Page.context.getClientUrl();
var entityId = Xrm.Page.data.entity.getId();
var workflowId = '8b386814-6a3d-4b3c-93a4-e6aaa1bb0b92';
var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
url = url + OrgServicePath;
var request;
request = "<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/\'>" + entityId + "</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/\'>" + workflowId + "</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<b:key>testinput</b:key>" +
"<b:value i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>Some Text</b:value>" +
"</a:KeyValuePairOfstringanyType>" +
"</a:Parameters>" +
"<a:RequestId i:nil=\'true\' />" +
"<a:RequestName>ExecuteWorkflow</a:RequestName>" +
"</request>" +
"</Execute>" +
"</s:Body>" +
"</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, false)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(request);
var response = JSON.parse(req.responseText);
}
}
这是工作流类的主体
[Output("testoutput")]
[Default("")]
public OutArgument<String> testoutput { get; set; }
[Input("testinput")]
[Default("")]
public InArgument<String> testinput { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracer = executionContext.GetExtension<ITracingService>();
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
String input = this.testinput.Get<string>(executionContext);
this.testoutput.Set(executionContext, input + " aaaand testoutput");
}