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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

I need to insert a new incident into crm Entity

(0) ShareShare
ReportReport
Posted on by 20

This is my code:

public void GrabarNuevo(Guid queCuenta, Guid queUsuario)
{
using (OrganizationService service = new OrganizationService("NubitCrmNav"))
{
try
{
Microsoft.Xrm.Sdk.Entity caso = new Microsoft.Xrm.Sdk.Entity("incident");
caso.Attributes.Add("title", "titulo");
caso.Attributes.Add("description", "Lorem Ipsum");

Microsoft.Xrm.Sdk.EntityReference contactId = new Microsoft.Xrm.Sdk.EntityReference("contact", queUsuario); //ex. {5b3520d8-d9a4-eb11-b1ac-000d3aaff90f}
Microsoft.Xrm.Sdk.EntityReference accountId = new Microsoft.Xrm.Sdk.EntityReference("account", queCuenta);//ex. {de7df147-bece-eb11-bacc-000d3abc199c}

caso.Attributes["accountid"] = accountId;
caso.Attributes["contactid"] = contactId;
Guid incidentId = service.Create(caso);

}
catch (Exception ex) {
Console.Write("Error info:"   ex.Message);
}
}

}

Error is : 

You must specify a contact or account.
I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi anteOjo,

    In case(Incident) entity, customer field is one required field, you must fill it with account or contact when you create one case.

    pastedimage1626313423126v1.png

    Customer objContact = new Customer();
    
    objContact.type = EntityName.contact.ToString();
    
    objContact.Value = new Guid(contactID);
    
    myIncident.customerid = objContact;

    Note:

    Customer is one Contact, the Contact field should be empty.

    Customer is one Account, the Contact field should be child records for the account or empty.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Verified answer
    prt33k Profile Picture
    6,907 on at

    Hi,

    Case doesn't have account/contact OOB field - it does however has customer lookup which can be either contact or account. It also has primarucontactid which can be used to store contact.

    So you can change your code like :

    Microsoft.Xrm.Sdk.EntityReference contactId = new Microsoft.Xrm.Sdk.EntityReference("contact", queUsuario); //ex. {5b3520d8-d9a4-eb11-b1ac-000d3aaff90f}
    Microsoft.Xrm.Sdk.EntityReference accountId = new Microsoft.Xrm.Sdk.EntityReference("account", queCuenta);//ex. {de7df147-bece-eb11-bacc-000d3abc199c}
    
    caso.Attributes["customerid"] = accountId;
    caso.Attributes["primarycontactid"] = contactId;
    Guid incidentId = service.Create(caso);

    pastedimage1626318785116v1.png

    Thanks,

    PS

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 57 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 34 Most Valuable Professional

#3
Scott Jackson UK Profile Picture

Scott Jackson UK 22

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans