从Javascript调用工作流
我尝试在表单加载时从javascript库运行工作流。 但当我发送请求时,我收到以下错误消息: “岗位 500(内部服务器错误)' 在工作流的activitylog中,我看到它没有启动 我需要用一个参数(testinput)触发工作流,并需要接收工作流/输出的答案。 worklow定义为具有输入和输出的自定义活动从Javascript调用工作流,javascript,dynamics-crm,workflow,Javascript,Dynamics Crm,Workflow,我尝试在表单加载时从javascript库运行工作流。 但当我发送请求时,我收到以下错误消息: “岗位 500(内部服务器错误)' 在工作流的activitylog中,我看到它没有启动 我需要用一个参数(testinput)触发工作流,并需要接收工作流/输出的答案。 worklow定义为具有输入和输出的自定义活动 function RunWorkflow() { var _return = window.confirm('Are you want to execute workflow
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);
}
}
函数RunWorkflow(){
var _return=window.confirm('是否要执行工作流');
如果(返回){
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=“”+
"" +
"" +
"" +
"" +
"" +
“EntityId”+
“”+entityId+“”+
"" +
"" +
“WorkflowId”+
“”+workflowId+“”+
"" +
"" +
“测试输入”+
“一些文本”+
"" +
"" +
"" +
“ExecuteWorkflow”+
"" +
"" +
"" +
"";
var req=新的XMLHttpRequest();
请求打开(“POST”、url、false)
setRequestHeader(“接受”、“应用程序/xml、文本/xml、*/*”);
请求setRequestHeader(“内容类型”,“文本/xml;字符集=utf-8”);
请求setRequestHeader(“SOAPAction”http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
请求发送(请求);
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");
}
[输出(“测试输出”)]
[默认值(“”)
公共输出参数testoutput{get;set;}
[输入(“测试输入”)]
[默认值(“”)
公共InArgument测试输入{get;set;}
受保护的覆盖无效执行(CodeActivityContext executionContext)
{
ITracingService tracer=executionContext.GetExtension();
IWorkflowContext=executionContext.GetExtension();
IOOrganizationServiceFactory服务工厂=executionContext.GetExtension();
IOOrganizationService=serviceFactory.CreateOrganizationService(context.UserId);
尝试
{
字符串输入=this.testinput.Get(executionContext);
this.testoutput.Set(executionContext,input+“aaa”和testoutput”);
}
错误发生在您的服务器上,因此客户端脚本不太可能有帮助。@Archer如果您需要插件-它现在已连接,您可以在Web服务中设置断点并查看失败原因吗?500错误没有帮助。插件没有被调用-因此我无法调试它,因为它没有被触发。@Twiebie:您可以使用Fiddler和intercept服务器返回的实际响应。它通常包含有价值的详细信息。