Please check the code.
string sUrl="http://test:5555/xyz";
OrganizationServiceProxy sService = null;
Uri sOrganizationuri = new Uri("" + sUrl + "/XRMServices/2011/Organization.svc");
ClientCredentials sCredentials = new ClientCredentials();
sCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
sService = new OrganizationServiceProxy(sOrganizationuri, null, sCredentials, null);
sCaseId = Request.QueryString["incidentid"].ToString();
sService = Service.GetService(sUrl);
string strFetchIncident = @"<fetch mapping='logical' version='1.0'>" +
" <entity name='incident'>" +
" <attribute name='new_caseno' />" +
" <attribute name='title' />" +
" <attribute name='customerid' />" +
" <attribute name='new_customer' />" +
" <attribute name='ownerid' />" +
" <attribute name='incidentid' />" +
" <filter type='and'>" +
" <condition attribute='statecode' value='0' operator='eq'/>" +
" <condition attribute='incidentid' operator='eq' value='" + sCaseId + "' />" +
" </filter>" +
" </entity>" +
"</fetch>";
ErrHander.WriteError("Entity Collection");​
Log.WriteLog("Entity Collection");
EntityCollection ecObjects = (EntityCollection)sService.RetrieveMultiple(new FetchExpression(strFetchIncident));
if (ecObjects.Entities.Count > 0)
{
foreach (Entity ecObj in ecObjects.Entities)
{
if (ecObj.Attributes.Contains("incidentid"))
{
Guid gIncidentid = ecObj.GetAttributeValue<Guid>("incidentid");
Log.WriteLog("Incident Id" + gIncidentid);
string sIncidentid = gIncidentid.ToString();
if (sIncidentid.ToLower().Trim() == sCaseId.ToLower().Trim())
{
hidIncidentId.Text = gIncidentid.ToString();
if (ecObj.Attributes.Contains("customerid"))
{
EntityReference erAccountId = ecObj.GetAttributeValue<EntityReference>("customerid");
Log.WriteLog("Account Id" + erAccountId.Id);
Guid gAccountid = erAccountId.Id;
txtCompanyName.Text = erAccountId.Name.ToString();
hidAccountId.Text = erAccountId.Id.ToString();
}
if (ecObj.Attributes.Contains("ownerid"))
{
EntityReference erOwnerId = ecObj.GetAttributeValue<EntityReference>("ownerid");
Guid gOwnerid = erOwnerId.Id;
hidOwnerId.Text = erOwnerId.Id.ToString();
}
if (ecObj.Attributes.Contains("title"))
{
string sCaseTitle = ecObj.Attributes["title"].ToString();
Log.WriteLog("Case Title" + sCaseTitle);
hidCaseTitle.Text = sCaseTitle;
}
if (ecObj.Attributes.Contains("new_caseno"))
{
string sCaseno = ecObj.Attributes["new_caseno"].ToString();
txtIncidentNumber.Text = sCaseno;
}
}
}
}
}
protected void ibtnSubmit_Click(object sender, ImageClickEventArgs e)
{
sService = Service.GetService(sUrl);
Entity entCaseFeedback = new Entity("new_casefeedback");
if (txtIncidentNumber.Text != string.Empty)
{
entCaseFeedback["new_name"] = txtIncidentNumber.Text;
}
Guid gAccountID = Guid.Empty;
if (hidAccountId.Text != string.Empty)
{
gAccountID = new Guid(hidAccountId.Text);
Log.WriteLog("Button click Account Id" + gAccountID);
}
Guid gCaseID = Guid.Empty;
if (hidIncidentId.Text != string.Empty)
{
gCaseID = new Guid(hidIncidentId.Text);
Log.WriteLog("Button click Case Id" + gCaseID);
}
Guid gOwnerID = Guid.Empty;
if (hidOwnerId.Text != string.Empty)
{
gOwnerID = new Guid(hidOwnerId.Text);
}
entCaseFeedback["new_account"] = new EntityReference("account", gAccountID);
entCaseFeedback["new_casetitle"] = new EntityReference("incident", gCaseID);
entCaseFeedback["ownerid"] = new EntityReference("systemuser", gOwnerID);
if (rbtnEasePoor.Checked == true)
{
entCaseFeedback["new_ease"] = new OptionSetValue(100000000);
}
else if (rbtnEaseBelowAverage.Checked == true)
{
entCaseFeedback["new_ease"] = new OptionSetValue(100000001);
}
else if (rbtnEaseAverage.Checked == true)
{
entCaseFeedback["new_ease"] = new OptionSetValue(100000002);
}
else if (rbtnEaseGood.Checked == true)
{
entCaseFeedback["new_ease"] = new OptionSetValue(100000003);
}
else if (rbtnEaseExcellent.Checked == true)
{
entCaseFeedback["new_ease"] = new OptionSetValue(100000004);
}
entCaseFeedback["new_comments"] = txtComments.Text;
sService.Create(entCaseFeedback);
}
Thanks