Scenario: I am retriving all the records from an entity with a condition and tring to update a value of my option set to another value, if my condition satisfies.
For this I wrote the below code and I am getting an error "system.invalidcastexception.Microsoft Dynamics CRM has experienced an error". Can any tellme where I am exactly missing?
private void CheckIfInworkActions(ICrmContext context,Guid userId)
{
QueryExpression exe1 = new QueryExpression(avd_masteraction.EntityLogicalName);
exe1.ColumnSet.AddColumn(XrmAttributes.MasterAction.Status);
exe1.Criteria.AddCondition(XrmAttributes.StatusCode, ConditionOperator.Equal, 100000004);
var coll1 = context.OrganizationService.RetrieveMultiple(exe1);
foreach (Entity e in coll1.Entities)
{
if (coll1 != null && coll1.Entities != null && coll1.Entities.Count > 0)
{
OptionSetValue myOptionSet = new OptionSetValue();
myOptionSet.Value = 100000011;
e.Attributes[XrmAttributes.StatusCode] = myOptionSet.Value;
context.OrganizationService.Update(e);
}
}
}
*This post is locked for comments