locked
Send e-mail to the new customer.(mscrm2013) RRS feed

  • Question

  • Hi,

    This is my code for Send e-mail to the new customer.please check my code rectify my errors: (getting 4 errors

    1.Error    4    Type or namespace definition, or end-of-file expected ,Error2  Identifier expected, Error 3 Identifier expected ,Error 4  Expected class, delegate, enum, interface, or struct)

    using System;
    using System.Collections.Generic;
    using System.Text;

    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;

    namespace Microsoft.Crm.Sdk.Walkthrough
    {
        public class AccountCreateHandler : IPlugin
        {
        }
    }
    public void Execute(IPluginExecutionContext context)
    {
       DynamicEntity entity = null;

       // Check if the input parameters property bag contains a target
       // of the create operation and that target is of type DynamicEntity.
       if (context.InputParameters.Properties.Contains("Target") &&
          context.InputParameters.Properties["Target"] is DynamicEntity)
       {
          // Obtain the target business entity from the input parmameters.
          entity = (DynamicEntity)context.InputParameters.Properties["Target"];

          // Verify that the entity represents an account.
          if (entity.Name != EntityName.account.ToString()) { return; }
       }
       else
       {
          return;
       }

       try
       {
          // Create a task activity to follow up with the account customer in 7 days.
          DynamicEntity followup = new DynamicEntity();
          followup.Name = EntityName.task.ToString();

          followup.Properties = new PropertyCollection();
          followup.Properties.Add(new StringProperty("subject", "Send e-mail to the new customer."));
          followup.Properties.Add(new StringProperty("description",
             "Follow up with the customer. Check if there are any new issues that need resolution."));

          followup.Properties.Add(new CrmDateTimeProperty("scheduledstart",
             CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));
          followup.Properties.Add(new CrmDateTimeProperty("scheduledend",
             CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));

          followup.Properties.Add(new StringProperty("category",
             context.PrimaryEntityName));
     
          // Refer to the new account in the task activity.
          if (context.OutputParameters.Properties.Contains("id"))
          {
             Lookup lookup = new Lookup();
             lookup.Value = new Guid(context.OutputParameters.Properties["id"].ToString());
             lookup.type = EntityName.account.ToString();

             followup.Properties.Add(
                new LookupProperty("regardingobjectid", lookup));
          }

          TargetCreateDynamic targetCreate = new TargetCreateDynamic();
          targetCreate.Entity = followup;

          // Create the request object.
          CreateRequest create = new CreateRequest();
          create.Target = targetCreate;

          // Execute the request.
          ICrmService service = context.CreateCrmService(true);
          CreateResponse created = (CreateResponse)service.Execute(create);      
       }
       catch (System.Web.Services.Protocols.SoapException ex)
       {
          throw new InvalidPluginExecutionException(
             "An error occurred in the AccountCreateHandler plug-in.", ex);
       }
    }


    Thursday, May 8, 2014 12:45 PM

All replies

  • Hi ,

    the main execute method should be inside the iplugin interface.

    Then add proper reference to your application. It will work.

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    
    namespace Microsoft.Crm.Sdk.Walkthrough
    {
        public class AccountCreateHandler : IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
                DynamicEntity entity = null;
    
                // Check if the input parameters property bag contains a target
                // of the create operation and that target is of type DynamicEntity.
                if (context.InputParameters.Properties.Contains("Target") &&
                   context.InputParameters.Properties["Target"] is DynamicEntity)
                {
                    // Obtain the target business entity from the input parmameters.
                    entity = (DynamicEntity)context.InputParameters.Properties["Target"];
    
                    // Verify that the entity represents an account.
                    if (entity.Name != EntityName.account.ToString()) { return; }
                }
                else
                {
                    return;
                }
    
                try
                {
                    // Create a task activity to follow up with the account customer in 7 days. 
                    DynamicEntity followup = new DynamicEntity();
                    followup.Name = EntityName.task.ToString();
    
                    followup.Properties = new PropertyCollection();
                    followup.Properties.Add(new StringProperty("subject", "Send e-mail to the new customer."));
                    followup.Properties.Add(new StringProperty("description",
                       "Follow up with the customer. Check if there are any new issues that need resolution."));
    
                    followup.Properties.Add(new CrmDateTimeProperty("scheduledstart",
                       CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));
                    followup.Properties.Add(new CrmDateTimeProperty("scheduledend",
                       CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));
    
                    followup.Properties.Add(new StringProperty("category",
                       context.PrimaryEntityName));
    
                    // Refer to the new account in the task activity.
                    if (context.OutputParameters.Properties.Contains("id"))
                    {
                        Lookup lookup = new Lookup();
                        lookup.Value = new Guid(context.OutputParameters.Properties["id"].ToString());
                        lookup.type = EntityName.account.ToString();
    
                        followup.Properties.Add(
                           new LookupProperty("regardingobjectid", lookup));
                    }
    
                    TargetCreateDynamic targetCreate = new TargetCreateDynamic();
                    targetCreate.Entity = followup;
    
                    // Create the request object.
                    CreateRequest create = new CreateRequest();
                    create.Target = targetCreate;
    
                    // Execute the request.
                    ICrmService service = context.CreateCrmService(true);
                    CreateResponse created = (CreateResponse)service.Execute(create);
                }
                catch (System.Web.Services.Protocols.SoapException ex)
                {
                    throw new InvalidPluginExecutionException(
                       "An error occurred in the AccountCreateHandler plug-in.", ex);
                }
            }
        }
    }
    

    Regards,

    Priya.



    • Edited by PriyaSwain Monday, May 12, 2014 11:11 AM
    Monday, May 12, 2014 11:11 AM