Please wait, loading...

 

Create Activity Of An Phone Call On Create of Contact Using Plugin In MSCRM 2011 2013

March 24, 20141

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace ClassLibrary1
{
    public class Class1 : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
             serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            Contact test = (Contact)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));

            PhoneCall phone = new PhoneCall();

            ActivityParty _from = new ActivityParty();
            _from.PartyId = new EntityReference(SystemUser.EntityLogicalName, context.UserId);

            ActivityParty _to = new ActivityParty();
            _to.PartyId = new EntityReference(Contact.EntityLogicalName, test.Id);

            phone.From = new ActivityParty[] { _from };
            phone.PhoneNumber = “9028170672”;
            phone.DirectionCode = true;   // true is for outgoing and false is for incoming
            phone.Subject = “phone call trial”;
            phone.To = new ActivityParty[] { _to };
            service.Create(phone);
        }

    }
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

One comment

  • Unknown

    December 11, 2014 at 8:11 pm

    It Works! Thanks 🙂

Comments are closed.

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more