如何在Dynamics CRM 2016中使用ExecuteWorkflowRequest调用带参数的Action? [英] How to call Action with parameter(s) using ExecuteWorkflowRequest in Dynamics CRM 2016?
问题描述
上下文
我可以使用ExecuteWorkflowRequest成功调用操作,其中被调用操作没有参数:
I can successfully call Actions using ExecuteWorkflowRequest where the called action has no parameters:
var request = new ExecuteWorkflowRequest
{
EntityId = myEntityId,
WorkflowId = myWorkFlowId,
};
service.Execute(request);
其中action是一个简单的工作流,类别为"Action". 但是,我无法使用参数调用操作.
where action is a simple workflow, with Category "Action". However I can not call Actions with parameters.
到目前为止,我已经尝试过:
string myParameter = "Hello";
var inputArgumentCollection = new InputArgumentCollection();
inputArgumentCollection.Arguments.Add("MyParameterName", myParameter);
var request = new ExecuteWorkflowRequest
{
EntityId = myEntityId,
WorkflowId = myWorkFlowId,
InputArguments = inputArgumentCollection
};
service.Execute(request);
被调用的工作流是一个类别:动作,具有可选的字符串类型输入参数"MyParameterName"
The called Workflow is a Category: Action with an optional string type input parameter called "MyParameterName"
此调用会导致一个异常:
This call causes an exception saying:
此工作流无法运行,因为父工作流提供的参数与链接的子工作流中的指定参数不匹配.
This workflow cannot run because arguments provided by parent workflow does not match with the specified parameters in linked child workflow.
我也尝试过... 有些地方建议(没有证据)使用请求本身的Parameters集合为较早的CRM版本...虽然看起来很丑和/或错误,但我还是拍了一张,但没有成功:
I've also tried... Some places recommend (with no proof) for older CRM versions using the Parameters collection of the request itself... although it seems ugly and/or wrong, I gave it a shoot, with no success:
request.Parameters.Add("MyParameter", myParameter);
以
无法识别的请求参数:MyParameter
Unrecognized request parameter: MyParameter
问题
如何使用ExecuteWorkflowRequest通过API调用提供参数的参数化操作?
How can I call my parametrized Action providing parameters via API using ExecuteWorkflowRequest?
推荐答案
ExecuteWorkflowRequest
是为执行工作流而设计的请求,在较早版本的Dynamics CRM中尚不支持操作.无法将参数传递给它.
The ExecuteWorkflowRequest
is a request that was designed for executing workflows, in an older version of Dynamics CRM not yet supporting actions. It is not possible to pass arguments to it.
相反,您需要使用必需的参数创建一个动作并按如下所示执行它:
Instead you need to create an action with the required parameters and execute it like this:
var request = new OrganizationRequest("new_myaction")
{
// EntityReference to the target of the action (suggested custom parameter)
["Target"] = myEntityId,
// Another custom parameter
["MyParameterName"] = "Hello"
};
service.Execute(request);
"new_myaction"
是操作的逻辑名称.
这篇关于如何在Dynamics CRM 2016中使用ExecuteWorkflowRequest调用带参数的Action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!