Skip to main content

Notifications

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.
  • Verified answer
    prt33k Profile Picture
    6,907 on at
    RE: I need to insert a new incident into crm Entity

    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

  • Community Member Profile Picture
    on at
    RE: I need to insert a new incident into crm Entity

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,304 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans