I have an error with a script that contains multiple fetch in crm 2011... the error is that the key dosent exist & is coming from:
<condition attribute='bc_type' operator='eq' lable='Credit' value='948110001' />
if no recordes exist with the condition it fails rather then just pass & return 0 any ideas?
i do declare
decimal TotalDed = 0;
decimal TotalCre = 0;
The code:
string value_sum = string.Format(@"
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='bc_llbalance'>
<attribute name='bc_units' alias='ded_sum' aggregate='sum' />
<filter type='and'>
<condition attribute='bc_learninglicense' operator='eq' value='{0}' uiname='' uitype='' />
<condition attribute='bc_type' operator='eq' lable='Deduction' value='948110000' />
</filter>
</entity>
</fetch>", a);
EntityCollection value_sum_result = service.RetrieveMultiple(new FetchExpression(value_sum));
foreach (var b in value_sum_result.Entities)
{
TotalDed = ((Decimal)((AliasedValue)b["ded_sum"]).Value);
}
string cre_sum = string.Format(@"
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='bc_llbalance'>
<attribute name='bc_units' alias='cre_sum' aggregate='sum' />
<filter type='and'>
<condition attribute='bc_type' operator='eq' lable='Credit' value='948110001' />
<condition attribute='bc_learninglicense' operator='eq' value='{0}' uiname='' uitype='' />
</filter>
</entity>
</fetch>", a);
EntityCollection cre_sum_result = service.RetrieveMultiple(new FetchExpression(cre_sum));
foreach (var c in cre_sum_result.Entities)
{
TotalCre = ((Decimal)((AliasedValue)c["cre_sum"]).Value);
}
Thanks :)