1
votes

I am trying to insert a Case record using C#. My code is the following:

//Creating Case Record in CRM.
Entity entityName = new Entity("incident");
entityName["title"] = caseData.Title;
entityName["subjectid"] = ???;
entityName["description"] = caseData.Description;
entityName["prioritycode"] = new OptionSetValue(caseData.Priority);
entityName["customerid"] = new EntityReference("account", Guid.Parse(CustomerID));
organizationService.Create(entityName);

Please help me how to insert in Subject field.

Thank you in advance.

2

2 Answers

1
votes

Like Chris said, it has to be EntityReference.

For example, I filled in with a sample subjectid = 4bffff67-48ec-42d1-b5d7-01422e2bfc4e (subject tree node GUID) to test successfully.

//Creating Case Record in CRM.
Entity entityName = new Entity("incident");
entityName["title"] = caseData.Title;
entityName["subjectid"] = new EntityReference("subject", Guid.Parse("4bffff67-48ec-42d1-b5d7-01422e2bfc4e"));
entityName["description"] = caseData.Description;
entityName["prioritycode"] = new OptionSetValue(caseData.Priority);
entityName["customerid"] = new EntityReference("account", Guid.Parse(CustomerID));
organizationService.Create(entityName);
0
votes

It might be necessary to specify where this caseData is coming from.

Im assuming you have a list of subjects in dynamics?

if you are creating this from a form? You need to create a new service that will return you the list of subjects in dynamics. you could add a dropdown list onto your form which has its data populated from your new "SubjectService".

otherwise i would review what is expected in the subject field, what are the options? is there a generic option you can chose? do you have the data to allow you to programatically pick an option from the data in your "SubjectService" and find it's id?

either way i assume you are going to need an EntityReference like you have for the customer.