Just updated code and I'm getting an error when the FetchXML query returns no records.
This is what I have:
//Start A string estimatedvalue_sum = string.Format(@" <fetch distinct='false' mapping='logical' aggregate='true'> <entity name='opportunity'> <attribute name='estimatedvalue' alias='estimatedvalue_sum' aggregate='sum' /> <filter type='and'><condition attribute='statecode' operator='eq' value='2' /><condition attribute='new_servicecontract' operator='eq' value='{0}' uiname='' uitype='' /></filter></entity></fetch>", a.Id); EntityCollection estimatedvalue_sum_result = service.RetrieveMultiple(new FetchExpression(estimatedvalue_sum)); if (estimatedvalue_sum_result != null) { foreach (var c in estimatedvalue_sum_result.Entities) { totalAmount = ((Money)((AliasedValue)c["estimatedvalue_sum"]).Value).Value; } //updating the field on the account Entity acc = new Entity("wse_servicecost"); acc.Id = a.Id; acc.Attributes.Add("new_caseanalysisopenbalance", new Money(totalAmount)); service.Update(acc); }
Does anyone know how to correct this?