1
votes

I have created a plugin (using Developer's tool kit) which will send a mail to Participants, which is converted Contacts, whenever a Participants is created. But this plugin is not Working. When I was trying to debug it this following message came in plugin registration tool(SDK)

Profiler> Plug-in AppDomain Created
Profiler> Parsed Profiler File Successfully.
Profiler> Constructor Execution Started: XXXXXXXX
Profiler> Constructor Execution Completed Successfully (Duration = 8ms).
Profiler> Profiler Execution Started: XXXXXXXXXXX
Plug-in> Entered CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(), 
Plug-in> Exiting CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(),
Profiler> Profiler Execution Completed Successfully (Duration = 57ms).
Profiler> Profiler AppDomain Unloaded

. Pipeline Stage is Pre-Validation on Create Message. And this is my Code:

protected void ExecutePostParticipantCreate(LocalPluginContext localContext)
{
    if (localContext == null)
    {
        throw new ArgumentNullException("localContext");
    }

    // TODO: Implement your custom Plug-in business logic.

    IPluginExecutionContext context = localContext.PluginExecutionContext;
    IOrganizationService service = localContext.OrganizationService;

    if (context.InputParameters.Contains("Target") &&
        context.InputParameters["Target"] is Entity)
    {
        try
        {
            Entity entity = (Entity)context.InputParameters["Target"];
            if (entity.LogicalName == "new_participant")
            {
                Guid Contact_id = ((EntityReference)entity.Attributes["new_participantscontact"]).Id;


                Guid trip_Id = ((EntityReference)entity.Attributes["new_tripparticipants"]).Id;

                ColumnSet col1 = new ColumnSet("new_name", "new_date", "new_destination");
                Entity trip = service.Retrieve("new_trip", trip_Id, col1);
                var Trip_name = trip.Attributes["new_name"];
                var Trip_date = trip.Attributes["new_date"];
                var Trip_destination = trip.Attributes["new_destination"];
                string emailBody = "Hi, your " + Trip_name.ToString() + "is booked on : " + Trip_date.ToString() + "; Destination : " + Trip_destination.ToString();
                Guid _userId = context.UserId;

                ActivityParty fromParty = new ActivityParty
                {
                    PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId)
                };


                ActivityParty toParty = new ActivityParty
                {
                    PartyId = new EntityReference("new_participantscontact", Contact_id)
                };

               Email email = new Email
                    {
                    To = new ActivityParty[] { toParty },
                    From = new ActivityParty[] { fromParty },
                    Subject =Trip_name.ToString()+ "  :Trip Details",
                    Description = emailBody,
                    DirectionCode = true
                    };

                Guid emailID = service.Create(email);

               SendEmailRequest req = new SendEmailRequest();
               req.EmailId = emailID;
               req.TrackingToken = "";
               req.IssueSend = true;

               SendEmailResponse res = (SendEmailResponse)service.Execute(req);
            }
        }
        catch (FaultException ex)
        {

            throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
        }
    }
}

Have I done any thing wrong here?

Thank you.

3
How do you know the plugin is not firing?James Wood
Sry its firing, I was profiling this plugin using SDK pluginregistration tool,while debugging nothing happendTamal Kanti Dey

3 Answers

1
votes

i think the first thing is discover if your plugin is fired or not. Try debug or use ITracingService to know that. If you discover that is your plugin isn't fired the code is unnecessary. Be careful that the deploy of a plugin in CRM Online has a limitation of running just in sandbox mode. Try see this step-by-step deploy of a plugin in CRM Online.

1
votes

Are you able to debug using the steps listed here: http://microsoftcrmworld.blogspot.com/2013/01/debug-plugins-on-your-local-pc-without.html ?

If not, you can add some localContext.trace() calls and then throw an exception at the very end of your execute method. Download and view the log file to see the outputs from localContext.trace(). This will give you an idea of what's going on.

0
votes

Your code seems to be fine... I observed that you are sending mail to a custom entity... Have you enabled "Sending Email" option during customization?

Check this link for enabling it