web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Dynamics CRM plugin failure on Create of contact

(0) ShareShare
ReportReport
Posted on by 10

Any help would be appreciated. This simple plugin shows no errors and registers fine but fails when a contact is created. 

It should simply create a follow-up task after contact is created. 

Here is the error: Generic. 

Exception Message: An error occurred in MyPlug-in.

ErrorCode: -2147220891
HexErrorCode: 0x80040265

ErrorDetails:
OperationStatus: 0
SubErrorCode: -2146233088
Plugin:
ExceptionFromPluginExecute: TaskCreate.TaskCreate
ExceptionRetriable: False
ExceptionSource: PluginExecution
OriginalException: PluginExecution
PluginTrace:

HelpLink: go.microsoft.com/.../

TraceText:
[HelloWorldPopulateDescriptionField: TaskCreate.TaskCreate]
[89954400-b2a3-ed11-aad1-000d3a2d2719: TaskCreate.TaskCreate: Create of contact]
Starting sync workflow 'Lock Company ID On Contact', Id: 247e8283-1e97-ed11-aad1-000d3a2d2719
Entering ConditionStep1_step:
Entering ConditionBranchStep2_step:
Sync workflow 'Lock Company ID On Contact' completed successfully

Activity Id: bc59adea-2a97-4572-add7-d48ad26374e1

Here is the code



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


namespace TaskCreate
{
public class TaskCreate : IPlugin
{

public void Execute(IServiceProvider serviceProvider)
{

ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));


IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));


IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{

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


try
{

// Plug-in business logic 
//When user creates a contact, a task must be created automatically by the system. The task should be completed within 2 days.

//this is an object not a new record - it is ready for the service.create to use this in memory object
Entity taskRecord = new Entity("task");

//this sets the single lines of text in the task
taskRecord.Attributes.Add("subject", "Follow up");

//date attribute populated in the task and set for 2 days later
taskRecord.Attributes.Add("scheduledend", DateTime.Now.AddDays(2));

//Set option set value attribute sets status
taskRecord.Attributes.Add("priority", new OptionSetValue(2));

//Set the Parent record attribute lookup regarding attribute on the task to ilnk it to parent contact
taskRecord.Attributes.Add("regardingobjectid", new EntityReference("contact", contact.Id ));

Guid taskGuid = service.Create(taskRecord);

}

catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
}

catch (Exception ex)
{
tracingService.Trace("MyPlugin: {0}", ex.ToString());
throw;
}
}
}
}
}

The code is signed and built. The plugin registration tool is used:
Create 

Contact 
PostOperation 

I would love to use the profiler to debug, but there is an error there, too, when I try to install it. You may think there is a link, but other plugins have registered fine and work and the issue is not with registering, it is at the point of a contact being created in CRM. 

I have the same question (0)
  • 4891s Profile Picture
    10 on at
    RE: Dynamics CRM plugin failure on Create of contact

    For those interested, I was going through it line by line and have figured out where the issue is coming from:

    //Set option set value attribute sets status

    taskRecord.Attributes.Add("priority", new OptionSetValue(2));

    Will now do a little digging into how to set this value according to Microsoft documentation correctly.

  • Verified answer
    Manoj Mane Profile Picture
    1,020 on at
    RE: Dynamics CRM plugin failure on Create of contact

    Hi ,

    You can refer the below article link to check the field data type wise Plugin Code.

    Link

    Thanks,
    Manoj Mane.

    Please mark this as VERIFIED if it helps. White check mark



  • 4891s Profile Picture
    10 on at
    RE: Dynamics CRM plugin failure on Create of contact

    Thank you Manoj. This is very helpful.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 120

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 120 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 56

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans