Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Update record on Plugin - Object reference not set to an instance of an object

Posted on by 30

Hi,

I'm getting the exception: Object reference not set to an instance of an object, when trying to update an incident if I set a DateTime field (not required) through plugin code.

If I comment line below for the CloseDate, it works fine.

I can set it to null in SQL, but when trying to update the record through Excel, it throws same error as updating in the plugin code.

Not sure which could be the issue, it's very weird.

Again, field is not mandatory in CRM.

var entity = new Entity
{
    LogicalName = Incident.EntityLogicalName,
    Id = case.Id,
    Attributes = new AttributeCollection()
};

entity.Attributes.Add("new_closedate", null);

  • Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    But does the error come from this plugin you are showing to us? Because it seems that a different plugin or other process is trying to access that field and, since it's null, throws that error. Can you provide the error log, please?

  • Gresziu Profile Picture
    Gresziu 30 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    Thanks, but same issue

  • Suggested answer
    Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    Try this:

    entity.Attributes.Add("new_closedate", (DateTime?) null);

  • Gresziu Profile Picture
    Gresziu 30 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    When setting to utc now, it works

  • Gresziu Profile Picture
    Gresziu 30 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    Hi, 

    yes Id has value. I write its value to the trace. I only have the CaseID as (Guid), the case.Id in the code was to remove custom name.

  • Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    Hi,

    What happens if you update with a real DateTime value? Like DateTime.UtcNow?

    Regards,

    Joana

  • Suggested answer
    Kipetcoff Profile Picture
    Kipetcoff 1,002 on at
    RE: Update record on Plugin - Object reference not set to an instance of an object

    Hi,

    Have you checked this sentence? Id = case.Id. May be case is null.

    If you already retrive "case", why don't you update property directly?

    case["new_closedate"] = null

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

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans