Reputation: 95
I have set up a ServiceEndpoint in Dynamics 365 to send messages to Azure Service Bus. Whenever there is an update on an Account Entity a message is queued. I have a service that is listening on this queue. My service is updating a property on the Account Entity that was queued.
My code is not executed as a plugin and does not implement IPlugin. This means that I do not have access to the IPluginExecutionContext. To avoid an infinite loop I would like to use the CorrelationId as a context for my update calls.
Is this possible?
This is what happens:
My calls are using OrganizationServiceProxy
Upvotes: 0
Views: 727
Reputation: 5531
Why not use RemoteExecutionContext Class
Very quickly you can turn your Json(message) from Azure queue into Dynamics plugin context
private static RemoteExecutionContext GetContext(string contextJson)
{
_log.Verbose($"Inside function {nameof(RemoteExecutionContext)}");
RemoteExecutionContext rv = null;
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(contextJson)))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(RemoteExecutionContext));
rv = (RemoteExecutionContext)ser.ReadObject(ms);
}
_log.Verbose($"Exit function {nameof(RemoteExecutionContext)}");
return rv;
}
and you can call it something like below
RemoteExecutionContext pluginContext = GetContext(receivedBody);
Your issue is not with RemoteExecutionContext rather it is with trigger of plugin on Update of Account for Azure service bus. You might know you can restrict update of Account to run only on fields you wish rather than all i.e you can get message in your ASB queue on update of certain fields of Account.
In addition if you want to handle with code, there is something called shared variables in Plugins. You can use them.
Upvotes: 1