为了账号安全,请及时绑定邮箱和手机立即绑定

CRM 工作流:如何从子网格中获取所有记录作为实体列表并执行多次检索

CRM 工作流:如何从子网格中获取所有记录作为实体列表并执行多次检索

C#
婷婷同学_ 2021-10-24 14:12:06
正如标题所暗示的,我不知道如何将 entity.attributes ["subgrid"] 转换为实体列表,在其上运行多重检索:我现在的代码:protected override void Execute(CodeActivityContext executionContext)    {        ITracingService tracingService = executionContext.GetExtension<ITracingService>();        IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();        IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);        var entity = (Entity)context.InputParameters["Target"];        if (entity.LogicalName != "account")        {            return;        }        var currentAccountId = entity.Id;        try        {            if (!entity.Contains("Subgrid"))            {                return;            }            var itemsOnSubgrid = entity.Attributes["Subgrid"];            if(itemsOnSubgrid == null)            {                return;            }            else            {                //if subgrid exist and is not null                //List of entities needed            }        }        catch (Exception ex)        {            tracingService.Trace("MyWorkflow: {0}", ex.ToString());            throw new InvalidPluginExecutionException(ex.Message);        }    }
查看完整描述

2 回答

?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

假设您正在寻找一种方法来获取特定记录的所有关联记录。


如果是这样的话,我会写这样的东西。希望有帮助。


private EntityCollection GetAssociatedRecords(string relationshipName, string relatedEntityName, string entityName, Guid entityId,OrganizationService service)

        {

            EntityCollection result = null;

            try

            {

                QueryExpression query = new QueryExpression();

                query.EntityName = relatedEntityName;

                query.ColumnSet = new ColumnSet(false);

                Relationship relationship = new Relationship();

                relationship.SchemaName = relationshipName;

                relationship.PrimaryEntityRole = EntityRole.Referencing;

                RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();

                relatedEntity.Add(relationship, query);

                RetrieveRequest request = new RetrieveRequest();

                request.RelatedEntitiesQuery = relatedEntity;

                request.ColumnSet = new ColumnSet(true);


                request.Target = new EntityReference

                {

                    Id = entityId,

                    LogicalName = entityName

                };

                RetrieveResponse response = (RetrieveResponse)service.Execute(request);

                RelatedEntityCollection relatedEntityCollection = response.Entity.RelatedEntities;

                if (relatedEntityCollection.Count > 0)

                {

                    if (relatedEntityCollection.Values.Count > 0)

                    {

                        result = (EntityCollection)relatedEntityCollection.Values.ElementAt(0);

                    }

                }

            }

            catch (Exception exception)

            {

                throw exception;  

            }

            return result;

        }

根据其他实体的角色,在引用和引用之间更改主要实体角色。


希望有帮助。让我知道我的假设是否错误。


查看完整回答
反对 回复 2021-10-24
?
慕容708150

TA贡献1831条经验 获得超4个赞

当您在自定义工作流程序集中编写代码时 - 此时的实体对调用它的表单一无所知,并且没有允许您访问相关记录的“子网格”属性。

您将需要使用目标实体的“accountid”属性与联系人的“parentcustomerid”属性相关联,执行单独查询以检索相关联系人(作为示例)。


查看完整回答
反对 回复 2021-10-24
  • 2 回答
  • 0 关注
  • 165 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信