web
You’re offline. This is a read only version of the page.
close
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());
}

}

}
}
}

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 41

#2
Martin Dráb Profile Picture

Martin Dráb 38 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans