Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CloseIncidentRequest NullReferenceException error

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Greetings experts,

I'm trying to use a plugin that opens an incident, updates a value and closes again. I'm using the following code for this:

--

//Reopen Case

OptionSetValue opencasestatedcode = new OptionSetValue();
opencasestatedcode.Value = 0;
OptionSetValue opencasestatuscode = new OptionSetValue();
opencasestatuscode.Value = 1;

casentity["statuscode"] = opencasestatuscode;

casentity["statecode"] = opencasestatedcode;
service.Update(casentity);

//Update Total Time
casentity["new_total_time"] = 60;
service.Update(casentity);

// Create the incident's resolution.
var incidentRes = new IncidentResolution
{
Subject = "Resolved Sample Incident",
IncidentId = new EntityReference(Incident.EntityLogicalName, (Guid)casentity.Attributes["incidentid"])
};

// Close the incident with the resolution.

var closeIncidentRequest = new CloseIncidentRequest
{
IncidentResolution = incidentRes,
Status = new OptionSetValue(5)
};

_serviceProxy.Execute(closeIncidentRequest);

--

But during the execution, it throws the following error: System.NullReferenceException: Object reference not set to an instance of an object

Any ideas about what am I doing wrong?

*This post is locked for comments

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: CloseIncidentRequest NullReferenceException error

    Hi

    My first thought is you are using service.Update and _serviceProxy.Execute(closeIncidentRequest);.  service or _serviceProxy is null.

    Could you please try adding trace lines to plugin to see if it failed on update (service.Update(casentity)) or _serviceProxy.Execute(closeIncidentRequest);

    When the plugin throws exception, if you download the log file you should be able to see which step failed

    I would also enable plugin trace log : ssharmacrm.wordpress.com/.../dynamics-crm-enable-plugin-trace-log

    On a side note, like other Gautum suggested, case cannot be re-opned using Update, you have to use  SetStateRequest. But i think in your case the code seems to fail before it gets to the actual Update or execute.

    Hope this helps

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: CloseIncidentRequest NullReferenceException error

    Hi ,

    I think it will be good if you share your full code as the error says  that null object reference.

    I can see you are using first  service.Update then again _serviceProxy.Execute.

    Which is correct object service or _serviceProxy?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: CloseIncidentRequest NullReferenceException error

    Try to replace line

    IncidentId = new EntityReference(Incident.EntityLogicalName, (Guid)casentity.Attributes["incidentid"])

    with line

    IncidentId = new EntityReference(Incident.EntityLogicalName, casentity.Id)

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans