Announcements
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.
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);
Thanks,
PS
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.
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.
André Arnaud de Cal...
293,304
Super User 2025 Season 1
Martin Dráb
232,149
Most Valuable Professional
nmaenpaa
101,156
Moderator