HexErrorCode: 0x80040224
[TestD365: FirstPlugin.HelloWorld]
[76f8cb80-620d-ef11-9f89-0022486e22c5: FirstPlugin.HelloWorld: Create of contact]
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
{
public class HelloWorld : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Extract the tracing service for use in debugging sandboxed plug-ins.
// If you are not registering the plug-in in the sandbox, then you do
// not have to add any tracing service related code.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains(/Target/) &&
context.InputParameters[/Target/] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters[/Target/];
{
// TODO Plug-in business logic goes here. You can access data in the context,
// and make calls to the Organization web service using the Dataverse SDK.
if(entity.Attributes.Contains(/firstname/))
{
firstName = entity.Attributes[/firstname/].ToString();
}
{
throw new InvalidPluginExecutionException(/An error occurred in MyPlug-in./, ex);
}
{
tracingService.Trace(/MyPlugin: {0}/, ex.ToString());
throw;
}
}
}
}
}