Hello,
I am currently writing a plugin and want to set a field. I can read the field from the opportunity but I cannot write it back somehow. Here is the code:
// global class variable
private const string FieldName_CloneFlag = "pref_cloneflag_boolean";
// [...some more plugin code to retrieve the entity...]
// check the clone flag... if (entity.Contains(FieldName_CloneFlag)) { tracingService.Trace("CloneFlag found"); if (!(bool)entity.Attributes[FieldName_CloneFlag]) { tracingService.Trace("CloneFlag = false... Leaving now."); return; } else { tracingService.Trace("CloneFlag = true... Setting to false now."); // remove the clone flag... Entity e = new Entity(entity.LogicalName); e.Id = entity.Id; e.Attributes.Add(FieldName_CloneFlag, false);
tracingService.Trace("attempting to update now..."); iOrgService.Update(e); tracingService.Trace("updated."); } }
The result in the Plug-In Trace Log is as follows:
CloneFlag found
CloneFlag = true... Setting to false now.
attempting to update now...
PluginClone Exception: 'opportunity' entity doesn't contain attribute with Name = 'pref_cloneflag_boolean' and NameMapping = 'Logical'.
What is weird for me is that I can chose the field in the PluginRegistration toll as filter and read its value in the code. What could be the reason why CRM thinks that the field does not exist?
Thanks!