Retrieving a value from MSCRM and and Assign it to another Variable

We can retrieve data from MS CRM, like we retrieve data from a database. For that as in the below code, we have to first specify the attributes which we want to consider while retrieving by using ColumnSet class.

Then we can specify the conditions to be consider using the ConditionExpression class.
Also we can specify a condition operator like in SQL queries by using that class.

Then we can filter the given condition using FilterExpression class. After that we can create a query to retrieve data using QueryExpression class. By using that query we can retrieve the data as shown in below code.

ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "name", "accountnumber" }; //name and accountnumber are two attributes.

ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "accountnumber"; // Get values corresponding to accountnumber value
condition.Operator = ConditionOperator.Equal;
condition.Values = new string[] { str1[0].Trim() };

FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { condition };

QueryExpression query = new QueryExpression();
query.EntityName = EntityName.account.ToString();
query.ColumnSet = cols;
query.Criteria = filter;

// Create the Web service request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;

// Execute the Web service request.
RetrieveMultipleResponse retrieved =

BusinessEntityCollection entities = retrieved.BusinessEntityCollection;
account ac = entities.BusinessEntities[0] as account;


Hope this will be helpful for you!!!

No comments:

Post a Comment

Getting Error Description and Error Column Name in SSIS 2016...

If you check the Error Output Path of a SSIS Data Flow component, it only contains the ErrorCode and the ErrorColumn (actually this the I...