locked
CRM 2015 online - Plugin for entity assign message RRS feed

  • Question

  • Hi,

    I am writing a plugin that I want to be triggered when a case entity is assigned. I don't need to check who it's assigned to, I just want the plugin to fire when the owner is updated. All I'm doing is setting a picklist on the form. 

    I have the code written, and have registered with the following values:

    Message: Assign

    Primary entity: incident

    Event Pipeline Stage of Execution:Pre-Operation

    Execution Mode: Synchronous

    Deployment: Server

    I can debug into it, and the plugin is being hit. However, I don't know how to get the target from the context.

    This is what I've tried, but it doesn't go inside the 'If':

      if ((context.InputParameters != null) && (context.InputParameters.Count > 0) && (context.InputParameters.Contains("Target")) && (context.InputParameters["Target"] is Entity))
                {
                    // Obtain the target entity from the input parameters.
                    target = (Entity)context.InputParameters["Target"];
                    
                }

    I have also tried this, to get a pre or post image. 'AssignMessage' is defined higher in the code, and is populated correctly.

    if (context.MessageName == AssignMessage)
                {
                    if ((context.PreEntityImages != null) && (context.PreEntityImages.Count > 0) && (context.PreEntityImages.Contains(PreImage) &&
                                 context.PreEntityImages[PreImage] is Entity))
                    {
                        preImage = (Entity)context.PreEntityImages[PreImage];
                    }
    
                    Trace("AssignMessage");
                    if ((context.PostEntityImages != null) && (context.PostEntityImages.Count > 0) && (context.PostEntityImages.Contains(PostImage)) && (context.PostEntityImages[PostImage] is Entity))
                    {
                        postImage = (Entity)context.PostEntityImages[PostImage];
                    }
                }

    Any ideas?

    Thanks.


    Friday, October 30, 2015 6:39 PM

Answers

  • For the Assign message, the Target is of type EntityReference, not Entity, so you want something like:

    EntityReference target = null;
      if ((context.InputParameters != null) && (context.InputParameters.Count > 0) && (context.InputParameters.Contains("Target")) && (context.InputParameters["Target"] is EntityReference))
                {
                    // Obtain the target entity reference from the input parameters.
                    target = (EntityReference)context.InputParameters["Target"];
                    
                }


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by crmNewbie1978 Sunday, November 1, 2015 1:20 PM
    Friday, October 30, 2015 10:51 PM
    Moderator

All replies

  • For the Assign message, the Target is of type EntityReference, not Entity, so you want something like:

    EntityReference target = null;
      if ((context.InputParameters != null) && (context.InputParameters.Count > 0) && (context.InputParameters.Contains("Target")) && (context.InputParameters["Target"] is EntityReference))
                {
                    // Obtain the target entity reference from the input parameters.
                    target = (EntityReference)context.InputParameters["Target"];
                    
                }


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by crmNewbie1978 Sunday, November 1, 2015 1:20 PM
    Friday, October 30, 2015 10:51 PM
    Moderator
  • Thanks for your help. I ended up using an update message instead, but I can see that the above would work.
    Sunday, November 1, 2015 1:20 PM