Retreive entity data and populate this details to other entity RRS feed

  • Question

  • i have two entities,retreive  one entity details and  populate this details  into other entity using 

    preimage or service in plugins.

     second entity record is created with a Status of “DRAFT”(first entity field) is created and also populate first entity  information.



    • Edited by Sindhu anne Wednesday, December 11, 2013 4:42 AM
    Tuesday, December 10, 2013 10:03 AM

All replies

  • Hi Sindhu,

    Here is a simple code to do that on update event through plugin:

    Entity ent = context.InputParameters["Target"] as Entity; if (ent.Contains("myEntityLookupField")) { EntityReference lookupReference = ent["myEntityLookupField"] as EntityReference; Entity referenceEntity = service.Retrieve(lookupReference.LogicalName, lookupReference.Id, new ColumnSet(true)); ent["attributeToGetFromReferenceEntity"] = referenceEntity["referenceEntityField"];

    service.Update(ent); }

    Given your execution context as 'context' and an IOrganizationService as 'service', and the two fields are of the same type. You can get the entity from preImage, too, in that case the first line will be the following:

    Entity ent = context.PreEntityImages["myImageName"] as Entity;

    I hope it helps.



    Tuesday, December 10, 2013 11:06 AM