Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

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

$
0
0

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'


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>