dynamics crm 2011 - The given key is not present in the dictionary -
hi trying fetch accounts crm 2011. fetching data in entitycollection . when trying read or access data entitycollection displayed first record throwing error after record. kindly have below code , suggest me.
string fetch2 = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='account'> <attribute name='name' /> <attribute name='address1_city' /> <attribute name='primarycontactid' /> <attribute name='telephone1' /> <attribute name='accountid' /> <order attribute='name' descending='false' /> <filter type='and'> <condition attribute='accounttype' operator='eq' value='01' /> </filter> </entity> </fetch>"; try { entitycollection fxresult = _service.retrievemultiple(new fetchexpression(fetch2)); foreach (var e in fxresult.entities) { console.writeline("id:{0},name:{1},city:{2}", e.attributes ["accountid"].tostring(), e.attributes["name"].tostring(), e.attributes["address1_city"].tostring()); // console.writeline("id:{0},name:{1},city:{2}", e.toentity["accountid"]); } } catch (exception e) { console.writeline("error:==" + e.message); }
before access attribute need ask if in context:
e.attributes.contains("address1_city")
if collection contains attribute, can access safe.
string accountid = (string)e.attributes["address1_city"]
the reason attribute doesn't come in collection it's because null or not retrieving it. in case maybe, 1 of attributes null. maybe address1_city.
Comments
Post a Comment