简体   繁体   English

将现有实体记录(竞争对手)关联到新记录(机会)crm d365 On create message

[英]Associate existing entity records (competitor) to new record (opportunity) crm d365 On create message

I have a requirement where I need to associate records from an entity 'competitor' to entity 'opportunity' in many to many relationship, on create of record, it's a plugin, and it shows null reference.我有一个要求,我需要在多对多关系中将实体“竞争对手”的记录关联到实体“机会”,在创建记录时,它是一个插件,它显示 null 参考。

code:代码:

        var opportunity = context.GetInputParameter<Entity>(InputParameters.Target);
      
        var postImage = context.HasPostImage(PostImageName) ? context.GetPostImage(PostImageName) : null;
        var competitors = opportunity.GetAttributeValue<string>(postImage,OpportunityDefinition.Columns.Competitors).Substring(9);
        var compet = JsonConvert.DeserializeObject<NTNMultiselect>(competitors);
        EntityReferenceCollection competitorsReferences = new EntityReferenceCollection();
        foreach (var comp in compet.actions)
        {
            Guid.TryParse(comp.guid, out Guid id);
            var competitorRef = new EntityReference(CompetitorDefinition.EntityName, id);
            competitorsReferences.Add(competitorRef);
        }
       
        //// The relationship to use
        var relationship = new Relationship("xxxxxxxxxxxxxxxxxxx");
        _service.Associate(opportunity.LogicalName, opportunity.Id, relationship, competitorsReferences);
        Console.WriteLine("The entities have been associated.");
    }

Registered on create, post-operation, synchronous, any ideas?注册创建,后期操作,同步,有什么想法吗?

Since this is a many-to-many (N: N) relationship, instead of trying to associate the records please try to create a record to the table "opportunitycompetitors".由于这是一个多对多 (N: N) 关系,因此不要尝试关联记录,而是尝试为“opportunitycompetitors”表创建一条记录。 That should help you to get both the records associated.这应该可以帮助您获得关联的两个记录。

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

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