传递参数给虚拟实体数据提供者插件

问题描述 投票:0回答:2

我的目标是在子网格上以自定义实体(例如,客户)的形式显示虚拟实体记录。我已经创建了一个虚拟实体、自定义数据提供程序并注册了所需的插件。到目前为止一切正常;我加载表单,子网格加载来自外部网络服务的数据。

现在,我想将表单上的一个字符串字段(例如,Client.ExternalId)作为参数传递给 retrieveMultiple 插件,以便我可以使用该字段来查询数据源。 retriveMultiple 插件步骤(在设置自定义数据提供者时自动注册)显示它是在虚拟实体而不是客户端实体上注册的。因为它是在客户端实体表单上加载子网格时执行的,所以我不确定如何将字段传递给插件。

有人可以就如何实现这一目标提供一些指导吗?

版本 1710 (9.2.22103.194) 上线

谢谢

plugins dynamics-crm
2个回答
0
投票

如果虚拟实体与主实体是N:1关系,并且子网格配置为显示相关记录,那么你可以这样做:

// first, get the whole query
var query = context.InputParameterOrDefault<QueryExpression>("Query");
// next, get the linkEntity and then the linkFilter
var linkFilter = query.LinkEntities.FirstOrDefault(x => x.LinkToEntityName == "mainEntityLogicalName").LinkCriteria;
// next, get the main entity id
var mainEntityId = linkFilter.Conditions.FirstOrDefault(x => x.AttributeName == "mainEntityIdFieldName").Values.FirstOrDefault() as Guid?;
// finally, retreive main entity to get the Client.ExternalId
var mainEntity = orgSvc.Retrieve("mainEntityLogicalName", mainEntityId.Value, new ColumnSet("Client.ExternalId"));
var clientExternalId = mainEntity.GetAttributeValue<string>("Client.ExternalId");

0
投票

最简单的方法必须是如果你做这个客户端,因为你想在加载表单时设置你的子网格。

var gridContext = page.getControl("YOURGRIDNAME");
var FetchXml = `<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
                  <entity name="msep_">
                    <attribute name="mserp_entityid" />
                    <attribute name="mserp_name" />
                    <filter type="and">
                      <condition attribute="mserp_entityid" operator="eq" value="` + id + `" />
                    </filter>
                  </entity>
                </fetch>`;
gridContext.setFilterXml(FetchXml);
page.getControl("YOURGRIDNAME").refresh();

您可以使用插件,但需要针对“检索多个”消息、预操作管道进行注册。输入参数将再次具有您可以操作的 fetchxml。

if (context.InputParameters["Query"] is FetchExpression) 
{
  var thisQuery = context.InputParameters["Query"];
  var fetchExpressionQuery = thisQuery as FetchExpression;
  fetchExpressionQuery.Query = "<fetch version'1.0'/>"
}
© www.soinside.com 2019 - 2024. All rights reserved.