简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM