3

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?

g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • I don't believe you can... (unless this was updated specifically in 2016): http://stackoverflow.com/questions/10978236/pass-a-parameter-to-a-crm-2011-workflow-via-the-api – Jason Faulkner Jun 22 '16 at 14:03

1 Answers1

4

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.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
  • This throws an error in CRM 2016 Online - 'unexpected error: Inheritance security rules violated while overriding member: 'Microsoft.Crm.CrmException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.' – Dead.Rabit Sep 27 '16 at 12:18
  • @Dead.Rabit: looks like a serialization error. Remember you cannot pass any object to an action. – Henk van Boeijen Sep 28 '16 at 06:33
  • I couldn't edit for some reason, but maybe change `myEntityId` to `myEntityRef` to avoid confusion. – Vicky Leong Mar 30 '17 at 17:26