Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Plugin not Triggered for Email Activities

$
0
0

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");
		}


Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>