Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Error while creating new record in "Appointment" entity with plugin

(0) ShareShare
ReportReport
Posted on by 15

I want to create a new record in "Appointment" entity with the help of plug-in code.  While i refreshing the page i got error 

Screenshot-_2800_330_2900_.png

My code is:::::   

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

namespace CreateAppointment
{
public class CreateAppointmentPlugin : IPlugin
{
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)
{


Entity entity = (Entity)context.InputParameters["Target"];

try
{
entity["subject"] = "Test Appointment";
entity["location"] = "patna";
entity["actualstart"] = "DateTime.Now.AddHours(1)";
entity["actualend"] = "DateTime.Now.AddHours(2)";
if (context.OutputParameters.Contains("id"))
{
entity["parentcustomerid"] = new EntityReference
{ Id = new Guid(context.OutputParameters["id"].ToString()), LogicalName = entity.LogicalName };
}
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService client = factory.CreateOrganizationService(context.UserId);
//client.Create(createappointment);
}
catch (InvalidPluginExecutionException ex)
{

throw new InvalidPluginExecutionException(ex.Message.ToString());
}

}

}
}
}

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: Error while creating new record in "Appointment" entity with plugin

    Hi,

    I see multiple issues in your code.

    Replace all entity[""] with below

    Entity appointment= new Entity("appointment");

    appointment ["subject"]="Test appointment"];

    Then pass appointment to client.Create

    You should also replace parentcustomerid with regardingobjectid

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,754 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans