I have following code to fetch an entity records:
private void FetchEvent(string EventId, IOrganizationService crmService)
{
// Create the ColumnSet to be retrieved.
ColumnSet columnSet = new ColumnSet();
// Set the properties of the ColumnSet.
columnSet.AddColumn("campaignid");
columnSet.AddColumn("name");
columnSet.AddColumn("description");
columnSet.AddColumn("renre_giftid");
columnSet.AddColumn("ownerid");
// Create the FilterExpression.
FilterExpression filterExpression = new FilterExpression();
// Create the ConditionExpression.
ConditionExpression conditionExpression = new ConditionExpression();
// Set the condition for the retrieval based on customer id field.
conditionExpression.AttributeName = "campaignid";
conditionExpression.Operator = ConditionOperator.Equal;
conditionExpression.Values.Add(new string[]{EventId});
filterExpression.FilterOperator = LogicalOperator.And;
// Set the properties of the filter.
filterExpression.Conditions.Add(conditionExpression);
// Create the QueryExpression object.
QueryExpression queryExpression = new QueryExpression();
// Set the properties of the QueryExpression object.
queryExpression.EntityName = "campaign";//EntityName.campaign.ToString();
queryExpression.ColumnSet = columnSet;
queryExpression.Criteria = filterExpression;
RetrieveMultipleRequest InvitationResponseRequest = new RetrieveMultipleRequest();
InvitationResponseRequest.Query = queryExpression;
//InvitationResponseRequest.ReturnDynamicEntities = true;
eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0];
}
When I debug, after reaching the last line of this function eventEntity = (Entity)((RetrieveMultipleResponse)crmService.Execute(InvitationResponseRequest)).EntityCollection.Entities[0];
It gives an exception that:
Please suggest.
You're passing a string array as the value of EntityId.
Change this:
conditionExpression.Values.Add(new string[]{EventId});
to this:
conditionExpression.Values.Add(new Guid(EventId));
You might also want to think about changing the type on the input parameter to a Guid and fixing the Pascal Casing on EventId argument to camel for consistency
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.