How to call Action with parameter(s) using ExecuteWorkflowRequest in Dynamics CRM 2016?

不打扰是莪最后的温柔 提交于 2019-12-14 02:07:06

问题


Context

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);

where action is a simple workflow, with Category "Action". However I can not call Actions with parameters.

What I've tried so far:

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);

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.

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);

returns with

Unrecognized request parameter: MyParameter

Question

How can I call my parametrized Action providing parameters via API using ExecuteWorkflowRequest?


回答1:


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);

Here "new_myaction" is the logical name of the action.



来源:https://stackoverflow.com/questions/37965325/how-to-call-action-with-parameters-using-executeworkflowrequest-in-dynamics-cr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!