简体   繁体   English

使用 CorrelationId 上下文更新 Dynamics 365 中的实体

[英]Updating entity in Dynamics 365 using CorrelationId context

I have set up a ServiceEndpoint in Dynamics 365 to send messages to Azure Service Bus.我在 Dynamics 365 中设置了一个 ServiceEndpoint 以将消息发送到 Azure 服务总线。 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.我的代码没有作为插件执行,也没有实现 IPlugin。 This means that I do not have access to the IPluginExecutionContext.这意味着我无权访问 IPluginExecutionContext。 To avoid an infinite loop I would like to use the CorrelationId as a context for my update calls.为了避免无限循环,我想使用 CorrelationId 作为更新调用的上下文。

Is this possible?这可能吗?

This is what happens:这就是发生的事情:

  1. Soemone updates or creates an account in Dynamics 365 Online Soemone 在 Dynamics 365 Online 中更新或创建帐户
  2. my service on my local server receives the message from Azure Service Bus我的本地服务器上的服务收到来自 Azure 服务总线的消息
  3. I parse the incomming JSON我解析传入的 JSON
  4. Verify that the Depth is not larger than 1 to avoid infinite loop验证Depth不大于1,避免死循环
  5. I retreive the Account Entity from Dynamics我从 Dynamics 检索帐户实体
  6. I make an update on a custom field我对自定义字段进行更新
  7. I update the Account Entity - Here is where it gets tricky.我更新了帐户实体 - 这是它变得棘手的地方。 My update request is generating a new message with a different CorrelationId.我的更新请求正在生成一条具有不同 CorrelationId 的新消息。 I would like the update request to use the CorrelationId of the incomming message so that I do not find my self in an infinite loop.我希望更新请求使用传入消息的 CorrelationId,这样我就不会在无限循环中找到自己。

My calls are using OrganizationServiceProxy我的电话正在使用 OrganizationServiceProxy

Why not use RemoteExecutionContext Class为什么不使用RemoteExecutionContext Class

Very quickly you can turn your Json(message) from Azure queue into Dynamics plugin context很快,您可以将您的 Json(message) 从 Azure 队列转换为 Dynamics 插件上下文

 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);

Article post for help 文章发帖求助

Your issue is not with RemoteExecutionContext rather it is with trigger of plugin on Update of Account for Azure service bus.您的问题与 RemoteExecutionContext 无关,而是与 Azure 服务总线的帐户更新上的插件触发器有关。 You might know you can restrict update of Account to run only on fields you wish rather than all ie you can get message in your ASB queue on update of certain fields of Account.您可能知道您可以限制帐户更新仅在您希望的字段上运行,而不是全部运行,即您可以在帐户的某些字段更新时在 ASB 队列中获取消息。

在此处输入图像描述

In addition if you want to handle with code, there is something called shared variables in Plugins .另外,如果你想处理代码, 在 Plugins 中有一个叫做共享变量的东西。 You can use them.你可以使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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