相关活动记录
所以事情是这样的:我创建了一个自定义实体“new_ligneContrat”,它具有一对多 与另一个自定义实体“new_produit”的关系。
目标是:当创建“new_ligneContrat”的新记录时,它必须获取之前“new_ligneContrat”的“new_produit”记录。该插件是基于“new_ligneContrat”构建的。
我想知道 FetchExpression + last() 是否可以做到这一点,但现在我还没有找到合适的解决方案...
提前致谢!
编辑1:我们决定为了建立 to n 关系,所以我做了以下事情:
QueryExpression query = new QueryExpression();
query.EntityName = "new_produit"; query.ColumnSet = new ColumnSet("new_produitid"); 关系关系=newRelationship(); 关系.SchemaName =“new_new_lignecontrat_new_produit”; 关系查询集合相关实体=新的关系查询集合(); relatedEntity.Add(关系,查询); RetrieveRequest 请求 = new RetrieveRequest(); request.RelatedEntitiesQuery = relatedEntity; request.ColumnSet = new ColumnSet("new_lignecontratid"); request.Target = 新的 EntityReference { Id = 第一个.Id, 逻辑名称 = 第一个.逻辑名称 }; RetrieveResponse 响应 = (RetrieveResponse)service.Execute(request);
if (((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new
> Relationship("new_new_lignecontrat_new_produit")) &&
> ((DataCollection<Relationship,
> EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new
> Relationship("new_new_lignecontrat_new_produit")].Entities.Count > 0)
> {
> response.Results.Remove("new_produitid");
> response["new_lignecontratid"] = new EntityReference(target.LogicalName, target.Id);
这是正确的吗?
So here is the thing : I created a custom entity "new_ligneContrat" which has a one-to-many
relationship with another custom entity "new_produit".
Here is the goal: when a new record of "new_ligneContrat" is created, it has to get the "new_produit" records of the "new_ligneContrat" before it. The plugin is built on "new_ligneContrat.
I was wondering if FetchExpression + last() could do it, but right now I haven't found the proper solution...
Thanks in advance !
Edit1 : We decided to go for a n to n relationship, so I did the following:
QueryExpression query = new QueryExpression();
query.EntityName = "new_produit"; query.ColumnSet = new ColumnSet("new_produitid"); Relationship relationship = new Relationship(); relationship.SchemaName = "new_new_lignecontrat_new_produit"; RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection(); relatedEntity.Add(relationship, query); RetrieveRequest request = new RetrieveRequest(); request.RelatedEntitiesQuery = relatedEntity; request.ColumnSet = new ColumnSet("new_lignecontratid"); request.Target = new EntityReference { Id = first.Id, LogicalName = first.LogicalName }; RetrieveResponse response = (RetrieveResponse)service.Execute(request);
if (((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new
> Relationship("new_new_lignecontrat_new_produit")) &&
> ((DataCollection<Relationship,
> EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new
> Relationship("new_new_lignecontrat_new_produit")].Entities.Count > 0)
> {
> response.Results.Remove("new_produitid");
> response["new_lignecontratid"] = new EntityReference(target.LogicalName, target.Id);
Is that correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

根据插件运行的插件执行阶段(验证前、操作前/操作后),一种选择是执行依赖于当前时间或 CreatedOn 属性的 LINQ 查询新的
new_ligneContrat
记录并调用First
方法来获取最新的new_produit
记录。我在下面添加了一个模型。Depending on which stage of the plugin execution your plugin is running in (pre-validation, pre/post-operation), one option is to execute a LINQ query that's dependent on the current time or the
CreatedOn
property of the newnew_ligneContrat
record and call theFirst
method to get the latestnew_produit
record. I've included a mockup below.