Click here to Skip to main content
15,896,528 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I have a requirement that i need to provide two contact fields for each case in MS Dynamics CRM.So i created a custom field " SecondaryContact "with dataType lookup(contact)for case(incident) entity in MS Dynamics CRM online.

now i want to pass value(contact id)from my appilication(in c#) to the custom field and also i want retrive all the cases based on custom field(contact Id) 

My code at present is to retrive all the cases based on PrimaryContactId
-----------------------------------------------
string primaryContactId = Session["ContactId"].ToString().Trim();
var context = new ForessCRMServiceContext(FssServiceProxy.orgService);
 var result = from r in context.IncidentSet where r.PrimaryContactId.Equals(primaryContactId) orderby r.CreatedOn descending select r;
foreach (Incident incident in result)
  {
	dr["TICKETID"] = incident.TicketNumber;
	dr["SUBJECT"] = incident.Title;
	dr["STATUS"] = incident.StatusCode.Value;
	dr["ROWNUMBER"] = iRowNumber;
	dr["INCIDENTID"] = incident.IncidentId;
	dt.Rows.Add(dr);
  }
---------------------------------------------------------
and iam creating case like this
---------------------------------------------------------
string primaryContactId = Session["ContactId"].ToString();          
IOrganizationService _service = FssServiceProxy.orgService;
Entity incident = new Entity();
incident.LogicalName = "incident";

incident["title"] = txtSubject.Text.Trim();
incident["description"] = txtDescription.Text.Trim();
string AccountId = ConfigurationManager.AppSettings["AccountId"] == null || ConfigurationManager.AppSettings["AccountId"].ToString().Trim().Equals("") ? "" : ConfigurationManager.AppSettings["AccountId"].ToString().Trim();
Guid customerid = new Guid(AccountId);

EntityReference CustomerId = new EntityReference("account", customerid);
incident["customerid"] = CustomerId;
Guid contactid = new Guid(primaryContactId);
EntityReference EprimaryContactId = new EntityReference("contact", contactid);
incident["primarycontactid"] = EprimaryContactId;
Guid TicketID = _service.Create(incident);
-------------------------------------------------------------
Kindly advise me to achive this


What I have tried:

i tried like below to retrieve the cases but iam getting error that " 'Incident' entity doesn't contain attribute with Name = 'SecondaryContact'."

QueryExpression query = new QueryExpression();
query.EntityName = "incident";
ColumnSet cols = new ColumnSet();
cols.AddColumns(new string[] { "ticketnumber", "title", "statecode", "incidentid", "SecondaryContact"});
query.ColumnSet = cols;
RetrieveMultipleResponse retrived = new RetrieveMultipleResponse();

RetrieveMultipleRequest retrive = new RetrieveMultipleRequest();
retrive.Query = query;
retrived = (RetrieveMultipleResponse)FssServiceProxy.orgService.Execute(retrive);

var result = retrived.Results;
Posted
Updated 28-Mar-16 5:15am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900