Skip to main content

Notifications

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. 

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

    Thank you Manoj. This is very helpful.

  • Verified answer
    Manoj Mane Profile Picture
    Manoj Mane 1,012 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
    4891s 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.

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans