Email Activity Creation Problem RRS feed

  • Question

  • I m new in MS Dynamic CRM 2013. I m trying to make a email activity on the update of a issue (case). but I m getting error at:

     CreateResponse resp = (CreateResponse)slos.Execute(reqActivity);

    I m attaching the whole code here:

    // <copyright file="PostIssueUpdate.cs" company="">
    // Copyright (c) 2015 All Rights Reserved
    // </copyright>
    // <author></author>
    // <date>1/29/2015 2:37:35 PM</date>
    // <summary>Implements the PostIssueUpdate Plugin.</summary>
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.1
    // </auto-generated>
    namespace CrmVSSolution1.Plugins
        using System;
        using System.ServiceModel;
        using Microsoft.Xrm.Sdk;
        using System.ServiceModel.Description;
        using System.Text;
        using System.Collections.Generic;
        using System.Linq;
        // These namespaces are found in the Microsoft.Xrm.Sdk.dll assembly
        // found in the SDK\bin folder.
        using Microsoft.Xrm.Sdk.Query;
        using Microsoft.Xrm.Sdk.Discovery;
        using Microsoft.Xrm.Sdk.Messages;
        using Microsoft.Xrm.Sdk.Client;
        using Microsoft.Crm.Sdk.Messages;
        /// <summary>
        /// PostIssueUpdate Plugin.
        /// Fires when the following attributes are updated:
        /// All Attributes
        /// </summary>    
        public class PostIssueUpdate: Plugin
            /// <summary>
            /// Initializes a new instance of the <see cref="PostIssueUpdate"/> class.
            /// </summary>
            public PostIssueUpdate()
                : base(typeof(PostIssueUpdate))
                base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "incident", new Action<LocalPluginContext>(ExecutePostIssueUpdate)));
                // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
                // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
            /// <summary>
            /// Executes the plug-in.
            /// </summary>
            /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
            /// <see cref="IPluginExecutionContext"/>,
            /// <see cref="IOrganizationService"/>
            /// and <see cref="ITracingService"/>
            /// </param>
            /// <remarks>
            /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
            /// The plug-in's Execute method should be written to be stateless as the constructor
            /// is not called for every invocation of the plug-in. Also, multiple system threads
            /// could execute the plug-in at the same time. All per invocation state information
            /// is stored in the context. This means that you should not use global variables in plug-ins.
            /// </remarks>
            protected void ExecutePostIssueUpdate(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)
                    // Obtain the target entity from the input parmameters.
                    Entity entity = (Entity)context.InputParameters["Target"];
                    if (entity.LogicalName == "incident")
                        string entityDescription = "There is no note found";
                            if (entity.Attributes.Contains(""))
                                entity.Attributes["description"] = entityDescription;
                            CreateRequest reqActivity = new CreateRequest();
                            Entity newEmail = new Entity("email");
                            newEmail["subject"] = "This is for testing";
                            newEmail["description"] = entityDescription;
                            Entity ap = new Entity();
                            Entity ap2 = new Entity();
                            ap = new Entity("activityparty");
                            ap["addressused"] = "xyz@xyz.com";
                            Entity[] aryTo = { ap };
                            newEmail["to"] = aryTo;
                            ap2 = new Entity("activityparty");
                            ap2["partyid"] = new EntityReference("systemuser", new Guid(""));
                            Entity[] aryFrom = { ap2 };
                            newEmail["from"] = aryFrom;
                            newEmail["regardingobjectid"] = new EntityReference("account", new Guid(""));
                            reqActivity.Target = newEmail;
                            CreateResponse resp = (CreateResponse)slos.Execute(reqActivity);
                        catch (FaultException ex)
                            throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);

    Thursday, January 29, 2015 9:26 AM

All replies

  • Hello,

    Could you please point to the part of your code where you have declared "slos"? I rechecked it twice and I see nothing. Also could you please provide an exception message that you are getting?

    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Thursday, January 29, 2015 10:12 AM