Hi all,
I have an entity with active and inactive records. I want to update the state of the record(from active to inactive).
For this I have written the code:
public static void CheckIfInworkActions(ICrmContext context)
{
QueryExpression exe= new QueryExpression(avd_agenthandlingtime.EntityLogicalName);
exe.ColumnSet.AddColumn(XrmAttributes.AgentHandlingTime.statecode);
exe.Criteria.AddCondition(XrmAttributes.StateCode, ConditionOperator.Equal, 0);
var coll1 = context.OrganizationService.RetrieveMultiple(exe);
foreach (Entity e in coll1.Entities)
{
if (coll1 != null && coll1.Entities != null && coll1.Entities.Count > 0)
{
e.Attributes["statecode"] = new OptionSetValue((int)1);
context.OrganizationService.Update(e);
}
}
}
can any one suggest me where I am going wrong?