Below is the sample code which explain retrieving CRM Account details based on the Account name.
I got sample code where you can get Account entity details if you pass guid, but didnot get sample code to retrieve Accoount details by Name.
So tried to give some sample where you can get Accoount details by name.
// Add authentication code here. you can get it from CRM SDK
// Create a column set that holds the names of the columns to be retrieved.
CRMService.CrmSdk.ColumnSet colsContact = new CRMService.CrmSdk.ColumnSet();
colsContact.Attributes = new string[] {"name", "accountid","new_status" };
// Create the ConditionExpression.
CRMService.CrmSdk.ConditionExpression conditionAccount = new CRMService.CrmSdk.ConditionExpression();
// Set the ConditionExpressions Properties so that the condition is true when
// the accountid or the contact is equal to accountId.
// Pass the filter value account id
//conditionContact.AttributeName = "accountid";
//conditionContact.Operator = CRMService.CrmSdk.ConditionOperator.Equal;
//conditionContact.Values = new string[] {"3455D9C5E-B311-DF43-A561-101E0B4CD088"};
// Pass the filter value account name
conditionAccount.AttributeName = "name";
conditionAccount.Operator = CRMService.CrmSdk.ConditionOperator.Equal;
conditionAccount.Values = new string[] { companyName };
// Create the FilterExpression.
CRMService.CrmSdk.FilterExpression filterAccount = new CRMService.CrmSdk.FilterExpression();
// Set the properties of the FilterExpression.
filterAccount.FilterOperator = CRMService.CrmSdk.LogicalOperator.And;
filterAccount.Conditions = new CRMService.CrmSdk.ConditionExpression[] { conditionAccount };
// Create the QueryExpression.
CRMService.CrmSdk.QueryExpression queryAccount = new CRMService.CrmSdk.QueryExpression();
// Set the properties of the QueryExpression.
queryAccount.EntityName = CRMService.CrmSdk.EntityName.account.ToString();
queryAccount.ColumnSet = colsContact;
queryAccount.Criteria = filterAccount;
// Retrieve the contacts.
CRMService.CrmSdk.BusinessEntityCollection myRetrievedAccount = crmService.RetrieveMultiple(queryAccount);
string accountId = string.Empty;
if (myRetrievedAccount != null && myRetrievedAccount.BusinessEntities[0] != null)
{
XPathNavigator navFields = default(XPathNavigator);
CRMService.CrmSdk.account myAccount = (CRMService.CrmSdk.account)myRetrievedAccount.BusinessEntities[0];
// get the values of accoount
accountId = myAccount.accountid.Value.ToString();
myAccount.new_status.name
No comments:
Post a Comment