locked
Plug In for Update EVENT RRS feed

  • Question

  •  

    Hi,

     

    How can i get the triggering entityid in my plugin code for update event.

    can i get it in both pre update and post update

     

     

     

     

     

     

    Tuesday, February 19, 2008 7:42 AM

Answers

  • You can get it from the Target that you get from InputParameters, e.g.

     

    DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];

    Guid id = entity["accountid"]; // Assuming the entity is an account

     

    This should work for both a pre and post update

     

    Tuesday, February 19, 2008 9:11 AM
    Moderator

All replies

  • You can get it from the Target that you get from InputParameters, e.g.

     

    DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];

    Guid id = entity["accountid"]; // Assuming the entity is an account

     

    This should work for both a pre and post update

     

    Tuesday, February 19, 2008 9:11 AM
    Moderator
  • Dear inputparamters..

     

    Entity["ID];  use the dynamicEntity model.. For more see CRM SDK.

     

    public class AccountSetStatePreHandler : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            // Create or retrieve some data that will be needed by the post event
            // handler. You could run a query, create an entity, or perform a calculation.
            //In this sample, the data to be passed to the post plug-in is
            // represented by a GUID.
            Guid contact = new Guid("{74882D5C-381A-4863-A5B9-B8604615C2D0}");

            // Pass the data to the post event handler in an execution context shared
            // variable named PrimaryContact.
            context.SharedVariables.Properties.Add(
                new PropertyBagEntry("PrimaryContact", (Object)contact.ToString()));
            // Alternate code: context.SharedVariables["PrimaryContact"] = contact.ToString();
        }
    }

    public class AccountSetStatePostHandler : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            // Obtain the contact from the execution context shared variables.
            if (context.SharedVariables.Contains("PrimaryContact"))
            {
                Guid contact =
                    new Guid((string)context.SharedVariables["PrimaryContact"]);
                // Do something with the contact.
            }
        }
    }

     

    Tuesday, February 19, 2008 10:19 AM
    Moderator
  • I am not able to get it in that way. It says the given key is not found in the dictionery .

     

     

    Guid accountid= new Guid(context.OutputParameters.Properties["id"].ToString());

     

    this brings me the GUID in post create, but the same thing is not working in  preupdate or post update events.

     

    Rgds,

    soumya.

     

    Tuesday, February 19, 2008 10:38 AM
  • Dear Imran,

     

    This looks complicated...

    so i cannot directly get the accountid of the updated account in my code as we do in callout?

     

    Tuesday, February 19, 2008 11:02 AM