【发布时间】:2018-02-16 09:19:26
【问题描述】:
我正在尝试从我的 C# 代码调用 Dynamics CRM 工作流。我的工作流程需要来自我的 C# 代码的参数。我正在使用流动代码:
var workflowInfo = result.Entities.FirstOrDefault();
if (workflowInfo != null)
{
InputArgumentCollection inputParameters = new InputArgumentCollection();
EntityReference reference = new EntityReference();
reference.Id = paymentRunID;
reference.Name = "paymentrunid";
reference.LogicalName = "paymentrun";
inputParameters.Add("InputPaymentRunID", reference);
inputParameters.Add("InputPaymentDueDate", paymentRunPayDate);
OptionSetValue opt = new OptionSetValue();
opt.Value = region;
inputParameters.Add("InputRegion", opt);
var request = new ExecuteWorkflowRequest();
request.WorkflowId = workflowInfo.GetAttributeValue<Guid>("workflowid"); //ID of the workflow to execute
request.EntityId = paymentRunID; //ID of the record on which the workflow executes
request.InputArguments = inputParameters;
ServerConnection.CrmService.Execute(request);
return true;
}
我的 CRM 工作流程端的代码是:
[RequiredArgument]
[Input("EntityReference input")]
[ReferenceTarget("paymentrun")]
public InArgument<EntityReference> InputPaymentRunID { get; set; }
[Input("DateTime input")]
public InArgument<DateTime> InputPaymentDueDate { get; set; }
[Input("OptionSetValue input")]
[Default("1")]
[AttributeTarget("paymentrun", "lregion")]
public InArgument<OptionSetValue> InputRegion { get; set; }
当我运行我的 C# 代码时,它已成功执行并返回 true,但在我的 Dynamics CRM 工作流程端,我收到以下错误:
This workflow cannot run because arguments provided by parent workflow does not match with the specified parameters in linked child workflow. Check the child workflow reference in parent workflow and try running this workflow again.
Unhandled Exception: Microsoft.Crm.CrmException: This workflow cannot run because arguments provided by parent workflow does not match with the specified parameters in linked child workflow. Check the child workflow reference in parent workflow and try running this workflow again.
at Microsoft.Crm.Workflow.Services.InputArgumentValidator.VerifyAndFilterInputParametersSupplied(Dictionary`2 inputArguments, Dictionary`2 childParameters)
at Microsoft.Crm.Workflow.ActivityHostBase.FetchInputArguments(ICommonWorkflowContext context)
at Microsoft.Crm.Workflow.ActivityHost.StartWorkflowExecution(Activity workflow, ICommonWorkflowContext context)
at Microsoft.Crm.Workflow.ActivityHostBase.StartWorkflow(ICommonWorkflowContext context, Activity preLoadedActivity)
C# 代码或工作流代码有什么问题。
【问题讨论】:
-
您提供的代码中的
dynamics部分不是Workflow它是custom activity。要使其运行,您应该将其用作workflow的一部分,它将在您的自定义步骤中提供参数(基于自定义活动)。请检查您的Workflow内容(不是Activity),如果仍然没有给出答案,请在问题中分享内容 -
必须查看调用此自定义 WF 活动的 UI 工作流屏幕截图。似乎有些孩子WF被称为,对吧?从 CRM UI 触发时,此 UI 工作流是否成功运行? (可按需提供)
标签: c# dynamics-crm