Notifications
Announcements
No record found.
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 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.
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
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 57 Super User 2025 Season 2
Daniyal Khaleel 34 Most Valuable Professional
Scott Jackson UK 22