locked
Plugin not Triggered for Email Activities RRS feed

  • Question

  • Hello,

    I'm writing a plugin that triggers when Phone, Task and Email status is changed to Completed or Cancelled. 

    So for this I register the plugin on the SetState and SetStateDynamicEntity on the three activities Phone, Task and Email. The stage is during Post-operation and Synchronous for all of these Activity types.

    The plugin is correctly triggered when closing Tasks and Phones. However it is not triggered when an email is sent. After sent the email is changed into Completed status but for some reason it never triggers the plugin whatsoever.

    I even try to hard-code the status of the email (statuscode) but it never triggers the plugin either.

    I'm using PostImage in my code which is correctly registered for all of the Activity types.

    Here's a portion of my code:

    Any suggestion is appreciated. Thanks,

    -tri

    public override void OnExecute(IServiceProvider serviceProvider, IPluginExecutionContext context)
            {
                var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
                // The InputParameters collection contains all the data passed in the message request.
                var targetReference = context.GetParameterCollection<EntityReference>(context.InputParameters, "EntityMoniker");
    
                if (targetReference == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
    
                var state = (OptionSetValue)context.InputParameters["State"];
                var status = (OptionSetValue)context.InputParameters["Status"];
    
    
                if (state != null &&
                    (state.Value == (int)Schema.Activity.State.Completed || state.Value == (int)Schema.Activity.State.Canceled || status.Value == (int)Schema.Activity.Status.PendingSend))
                {
                    
    		throw new InvalidPluginExecutionException(OperationStatus.Succeeded, "This activity is closed.");
    		//for some reason this exception is thrown when changing status on Task & Phones but NEVER when sending out emails.
                    var postImage = context.PostEntityImages["PostImage"];
    
                    if (postImage == null)
                        throw new InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");
    		}
                    
    

    Wednesday, December 16, 2015 8:35 PM

Answers

  • Ok I was mistaken that the Send message doesn't have any 'Target' parameter. So instead I get the 'EmailId' from the Execute method. This is working now, thanks everyone for the inputs.
    • Marked as answer by triangular Friday, January 8, 2016 9:09 PM
    Monday, December 28, 2015 10:24 PM

All replies

  • Hi, Try using the Send Message for email instead of setstate

    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    Thursday, December 17, 2015 5:23 AM
  • trigger you plugin o setstate as well as on Send messages

    Regards Faisal

    Thursday, December 17, 2015 12:21 PM
  • Hello all thanks for the reply. Sorry didn't realize all the replies here because for some reason I didn't get any email alerts on this topic...

    I tried registering my plugin on Email Send, SetState and SetDynamicState now. However this time I got an error message about null target entity...

    I tried registering the plugin on Pre-operation, but nothing gets triggered. When I tried Post-operation then for some reason there is no target entity...

    Any suggestion is greatly appreciated. Thanks,

    -tri

    public override void OnExecute(IServiceProvider serviceProvider, IPluginExecutionContext context)
            {
                var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
                // The InputParameters collection contains all the data passed in the message request.
                var targetReference = context.GetParameterCollection<EntityReference>(context.InputParameters, "EntityMoniker");
    
                if (targetReference == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
    Tuesday, December 22, 2015 10:00 PM
  • Ok I was mistaken that the Send message doesn't have any 'Target' parameter. So instead I get the 'EmailId' from the Execute method. This is working now, thanks everyone for the inputs.
    • Marked as answer by triangular Friday, January 8, 2016 9:09 PM
    Monday, December 28, 2015 10:24 PM