I am trying to update a field value of an entity in CRM using C#, but I am not sure how I should do it.
Below are my current code:
var helper = new CRMConnection();
var service = helper.OpenConnection();
var entiyRef = new Entity("financialaid");
string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='financialaid'>
<attribute name='financialaidid' />
<attribute name='emailcontent' />
</entity>
</fetch>";
var retrieved = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (retrieved != null && retrieved.Entities.Count > 0){
for (var k = 0; k < retrieved .Entities.Count; i++){
var emailContent = retrieved .Entities[i].GetAttributeValue<string>("emailcontent");
entiyRef["emailcontent"] = "test";
service.Update(entiyRef);
}
}
The code above returned over 5000
records, which I suppose that it is tied to every record I have in CRM. But I am just trying to update a standalone field in the entity.
After which, it hit the following error and exited.
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.Xrm.Sdk.dll
May I know how can I correctly update a field in CRM using FetchXML?
attributeId = 0AB038CE-E57E-EA11-A811-000D3AA3E77C
entityId = b6abe6f6-a876-4a80-87d6-2f1b179d437f
.retrieve
as I am unsure of aid
field, so I used.retrieveMultiple
instead. – gymcode