locked
Create relationship between entities RRS feed

  • Question

  • Dear,

    I want to add a relationship between 2 entities and I want to perform this using the Microsoft.Xrm.Sdk.Client object. I created an entity with the ID: ea01a1b6-74e1-4ce2-adc6-de2410b579e0. Now I want to add new entity that depends on this one. I used the following code. This code doesn't trow any errors, creates the entity, but it doesn't set the parenttag id. When we set this manually in the DB, the dependency is visible in CRM.

    OrganizationServiceProxy proxy = InitOrganizationServiceProxy();

    Guid tagId = new Guid("69ce592d-bc19-4d41-8bbf-2d83db0db9eb");

    Entity tag = new Entity(ENTITY_NAME);
    tag.Id = tagId;
    tag["tagname"] = "Child tag";
    tag["tagid2"] = tagId.ToString();
    tag["parenttag"] = new Guid("ea01a1b6-74e1-4ce2-adc6-de2410b579e0");//ea01a1b6-74e1-4ce2-adc6-de2410b579e0 is the ID of an existing entity

    Does somebody know how to set the relationship / whats wrong with the code?

    Thx!

    Monday, August 25, 2014 7:26 AM

Answers

  • Hi Francis,

    parentag field must be a lookup. And you can set the relationship like below.

    tag["parenttag"] = new EntityRefence("EntityName of ParentTagEntity", new Guid("ea01a1b6-74e1-4ce2-adc6-de2410b579e0");


    Polat Aydın Crm Software Developer

    Monday, August 25, 2014 7:36 AM

All replies

  • Hi Francis,

    parentag field must be a lookup. And you can set the relationship like below.

    tag["parenttag"] = new EntityRefence("EntityName of ParentTagEntity", new Guid("ea01a1b6-74e1-4ce2-adc6-de2410b579e0");


    Polat Aydın Crm Software Developer

    Monday, August 25, 2014 7:36 AM
  • Hi Polat,

    Thx a lot, this works!

    Monday, August 25, 2014 8:03 AM