Link to home
Start Free TrialLog in
Avatar of pbu-ts
pbu-tsFlag for United States of America

asked on

How do I create an appointment in Microsoft Dynamics CRM 2015 plugin?

I am trying to create an appointment as part of a plugin for Microsoft dynamics CRM 2015. I can successfully create tasks and other custom entities but the appointment creation fails. I am guessing I am missing something simple. Below is a sample of the relevant code.

        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
            {
                try
                {
                    Entity entity = context.PostEntityImages["PostImage"];
                    if (entity.LogicalName == "new_occasion")
                    {
                        tracingService.Trace("EventAppointmentSynchPlugin: Creating the appointment activity.");
                        
                        DateTime startTime = (DateTime)entity.Attributes["new_departureenddate"];
                        DateTime endTime = (DateTime)entity.Attributes["new_starttime"];

                        Entity ne = new Entity("appointment");

                        ne["subject"] = "Test Appointment";
                        ne["description"] = "Test Description";
                        ne["location"] = "Office";
                        ne["scheduledend"] = endTime;
                        ne["scheduledstart"] = startTime;

                        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                        service.Create(ne);
                    }
                    if (entity.LogicalName == "appointment")
                    {
                        throw new NotImplementedException();
                    }
                    else return;
                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the Plugin.", ex);
                }
                catch (Exception ex)
                {
                    tracingService.Trace("Plugin: {0}", ex.ToString());
                    throw;
                }
            }
            throw new NotImplementedException();
        }
                    

Open in new window

Avatar of Serena Hsi
Serena Hsi
Flag of United States of America image

Here is the SDK for Microsoft Dynamics CRM 2015:
https://www.microsoft.com/en-us/download/details.aspx?id=44567

Also, here is the community site for developing for Microsoft Dynamics:
https://msdn.microsoft.com/dynamics/crm/default.aspx
SOLUTION
Avatar of Rikin Shah
Rikin Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pbu-ts

ASKER

It was the solution.