web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Invoke Custom Action (with parameters) from C# Custom Workflow Assembly

(0) ShareShare
ReportReport
Posted on by

Good Afternoon, I'm writing a custom workflow, from this workflow I would like to call a custom action that's specified as an input parameter against a number of accounts that are dynamically retrieved by the workflow.

I've tried 4 separate approaches to calling the custom action: ExecuteWorkflowRequest, OrganizationRequest, CrmSvcUtil and using the OData endpoint, none of them seem to work in CRM Online (8.1.0.512). Finally, I also tried generating the early bound classes as suggested by the MSDN documentation to use to call the action, however my Action is not referenced in the generated classes despite being activated.

Please can anyone provide a link to sample code, or a blog where this is achieved, or provide any insight into why my approaches haven't worked.

1) Execute Workflow Request

So this was the technique from CRM 2013, I learnt it's not backwards compatible (though this caveat isn't documented as far as I can tell), which is a shame because if this is true, it's a huge gotcha` for developers who're new to the SDK. It complains that the parameters don't align, but I can assure you that they do!

service.Execute( new ExecuteWorkflowRequest()
{
EntityId = currentAccountRecord.Id,
WorkflowId = processRef.Id,
InputArguments = parameters
} );

Sync workflow '*' terminated with error 'unexpected error: 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.'

2) Organization Request

This is the approach I was most confident about, it works in CRM 2015 on-premise just fine, but in 2016 Online, I get an error about breaking the isolation rules...

var callActionReq = new OrganizationRequest( processRef.Name );
callActionReq["Target"] = currentAccountRecord.ToEntityReference();
foreach (var parameter in parameters)
{
callActionReq[parameter.Key] = parameter.Value;
}

service.Execute( callActionReq );

Sync workflow '*' terminated with error '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.'

3) OData endpoint

So I know this approach was a little cheeky, using the WebClient but I thought it was worth a shot!

string url = string.Format( "https://{0}.crm4.dynamics.com/api/data/v8.0/{1}s({2})/Microsoft.Dynamics.CRM.{3}",
context.OrganizationName,
currentAccountRecord.LogicalName,
currentAccountRecord.Id,
processRef.LogicalName );

using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.UploadString( url, "POST", json );
}

Sync workflow '*' terminated with error 'System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #ED50CBB2'

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    21 on at
    RE: Invoke Custom Action (with parameters) from C# Custom Workflow Assembly

    Are you throwing or inheriting from CrmException? You should use InvalidPluginExecutionException instead

  • jupton Profile Picture
    on at
    RE: Invoke Custom Action (with parameters) from C# Custom Workflow Assembly

    I've now resolved the error I mentioned above by passing Entity References between processes as strings. I've put more details about this in another thread.

    However, even though I'm now able to call the custom action from other workflows, I still receive the above error:

    <s:Envelope xmlns:s="schemas.xmlsoap.org/.../envelope"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring xml:lang="en-US">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.</faultstring><detail><OrganizationServiceFault xmlns="schemas.microsoft.com/.../Contracts" xmlns:i="www.w3.org/.../XMLSchema-instance"><ErrorCode>-2147220891</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic"><KeyValuePairOfstringanyType><a:key>OperationStatus</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">0</a:value></KeyValuePairOfstringanyType><KeyValuePairOfstringanyType><a:key>SubErrorCode</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">-2146233088</a:value></KeyValuePairOfstringanyType></ErrorDetails><Message>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.</Message><Timestamp>2016-09-27T11:34:59.162603Z</Timestamp><InnerFault><ErrorCode>-2147220891</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic"><KeyValuePairOfstringanyType><a:key>OperationStatus</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">0</a:value></KeyValuePairOfstringanyType><KeyValuePairOfstringanyType><a:key>SubErrorCode</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">-2146233088</a:value></KeyValuePairOfstringanyType></ErrorDetails><Message>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.</Message><Timestamp>2016-09-27T11:34:59.162603Z</Timestamp><InnerFault><ErrorCode>-2147220891</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic"><KeyValuePairOfstringanyType><a:key>OperationStatus</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">0</a:value></KeyValuePairOfstringanyType><KeyValuePairOfstringanyType><a:key>SubErrorCode</a:key><a:value xmlns:b="www.w3.org/.../XMLSchema" i:type="b:int">-2146233088</a:value></KeyValuePairOfstringanyType></ErrorDetails><Message>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.</Message><Timestamp>2016-09-27T11:34:59.162603Z</Timestamp><InnerFault i:nil="true"/><TraceText i:nil="true"/></InnerFault><TraceText i:nil="true"/></InnerFault><TraceText>
    [Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin]
    [f0666631-9e84-e611-80e4-c4346bad5038: ]
    Starting sync workflow '*', Id: eb666631-9e84-e611-80e4-c4346bad5038
    Entering ConditionStep1_step:
    Entering CustomActivityStep3_step:
    Sync workflow '*' terminated with error '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.'
    </TraceText></OrganizationServiceFault></detail></s:Fault></s:Body></s:Envelope>

  • jupton Profile Picture
    on at
    RE: Invoke Custom Action (with parameters) from C# Custom Workflow Assembly

    Yes, I've got another custom workflow step in the action I'm trying to call. I've already proven that step is working as expected though as it's reused a few times, so I didn't consider it! - great spot! Thankyou very much.

    When I try to invoke the custom action from another workflow using the UI tools, I get the following error as soon as I select the offending activity:

    Error generating UiData for workflow...

    System.ArgumentNullException: Value cannot be null.

    Parameter name: Empty Guid(s) passed to SecurityLibrary.CheckPrivilege

    The list of entities remains blank and I'm unable to set the parameters. If I remove that custom workflow step from the action, everything works as it should. Is there a way to work around this issue?

  • ScottDurow Profile Picture
    21 on at
    RE: Invoke Custom Action (with parameters) from C# Custom Workflow Assembly

    Do you have a plugin registered on your custom action? What happens if you try and call the custom action from another workflow - do you get an error?

    The OrganizationRequest is the approach I take all the time.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans