Hello People,
I have been trying to access a specific follow of a lookup field, I am kind of new to Dynamic CRM, so my code might be a bit off. My coe is below. Thanks
//var orgContext = new MedinetCRMService(GetOrgService());
new_hospital hospital = new new_hospital();
hospital.new_AddressOne = HAddressTextBox.Text.ToString();
hospital.new_name = HNameTextBox.Text.ToString();
Account trust = new Account();
QueryExpression trustQuery = new QueryExpression();
trustQuery.EntityName = "account";
trustQuery.ColumnSet = new ColumnSet("name");
trustQuery.Criteria.AddCondition(trust.Name, ConditionOperator.Equal, "BIRMINGHAM TRUST");
Guid accountid = Guid.Empty;
string accountName = "";
EntityCollection Collection = Service().RetrieveMultiple(trustQuery);
foreach (Account account in Collection.Entities)
{
accountid = account.Id;
accountName = account.GetAttributeValue<string>("name");
}
//Account account = (Account)GetOrgService().Retrieve(trust.LogicalName, trustID, new Microsoft.Xrm.Sdk.Query.ColumnSet("name"));
CrmEntityReference trustid = new CrmEntityReference(trust.LogicalName, accountid);
hospital.new_OwningTrustId = trustid;
Service().Create(hospital);
MessageBox.Show("succesfully added a hospital record");
I know, I am not meant to use retrieveMultiple at the first place. Thanks in advance
*This post is locked for comments
I have the same question (0)