Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Error checking in C#

$
0
0

what is the easiest way to check if a field value is null or nothing is returned in a collection? Try catch works for one or two fields, but I have like 15 that I need to use to create the sales order entity.

I want to be able to create an order entity even though there's no value and not break in the middle of the code. Is there a function I can use for each field without too much hassel?

Sample code:

This gets the account id by looking up the name of the customer.

var account = GetEntityCollection(_service, "account", "name", customerid, new ColumnSet("accountid", "name", "defaultpricelevelid"));
Guid accountId = (Guid)account[0].Id; 
salesorder["customerid"] = new EntityReference("account", new Guid(accountId.ToString()));

private static EntityCollection GetEntityCollection(IOrganizationService service, string entityName, string attributeName, string attributeValue, ColumnSet cols)
{
QueryExpression query = new QueryExpression
{
EntityName = entityName,
ColumnSet = cols,
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = attributeName,
Operator = ConditionOperator.Equal,
Values = { attributeValue }
}
}
}
};
return service.RetrieveMultiple(query);
}



Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>