locked
CRM 2011 Plugin Update Step RRS feed

  • Question

  • Hello Everyone,

    I can not get the Owner of the existing record using the script below. The form is on Update state!!!

    entity = (Entity)context.InputParameters["Target"];


    EntityReference OwnerId = (EntityReference)entity["ownerid"];

    Entity member = service.Retrieve("systemuser", OwnerId.Id, new ColumnSet(true));

    OwnerEmail

    Regards,

    Hussain


    hussain


    Tuesday, February 5, 2013 10:04 PM

Answers

  • The owner won't be in the target entity for an update step, only the fields that have changed.

    You just need to do another retrieve to get the current entity data:

    Entity current = service.Retrieve("entityname", context.PrimaryEntityId, new ColumnSet("ownerid"));
    EntityReference OwnerId = (EntityReference)current["ownerid"];

    You might also want to check if the OwnerId is in target first using if(entity.Contains("ownerid")), if it is then get it from target, otherwise get it using the method above.

    Hope that helps,

    Paul

    • Proposed as answer by MubasherSharif Wednesday, February 6, 2013 9:26 AM
    • Marked as answer by Hussain Saffar Wednesday, February 6, 2013 6:39 PM
    Tuesday, February 5, 2013 10:12 PM

All replies

  • The owner won't be in the target entity for an update step, only the fields that have changed.

    You just need to do another retrieve to get the current entity data:

    Entity current = service.Retrieve("entityname", context.PrimaryEntityId, new ColumnSet("ownerid"));
    EntityReference OwnerId = (EntityReference)current["ownerid"];

    You might also want to check if the OwnerId is in target first using if(entity.Contains("ownerid")), if it is then get it from target, otherwise get it using the method above.

    Hope that helps,

    Paul

    • Proposed as answer by MubasherSharif Wednesday, February 6, 2013 9:26 AM
    • Marked as answer by Hussain Saffar Wednesday, February 6, 2013 6:39 PM
    Tuesday, February 5, 2013 10:12 PM
  • Hi Hussain,

    You can register a postimage for the update step and then from the image you can get the ownerid.To use the postimage go through the following link.

    http://deepakexploring.wordpress.com/2011/02/04/preentityimages-and-postentityimages-in-crm-5-0-2011/

    Hope it helps you.



    Thank you, DT

    Wednesday, February 6, 2013 4:58 AM
  • Thank you Paul !!!!

    It works !!!! Yes yes


    hussain

    Wednesday, February 6, 2013 6:40 PM