Deactivating Records Of Custom Entity in CRM

by Matt 5. May 2010 14:50

I just spun my wheels a bit too much trying to solve a problem that wasn't really a problem at all.  I've been writing a plugin to set an instance of a custom CRM entity to inactive.  My code is:

EntityId = (Key)de.Properties["NameOfCustomEntity"];
id = EntityId.Value;
SetStateDynamicEntityRequest request = new SetStateDynamicEntityRequest();
request.Entity = new Moniker("KeyColumnName", id);
request.State = "Inactive";
request.Status = -1;
SetStateDynamicEntityResponse resp = (SetStateDynamicEntityResponse)service.Execute(request);

When I would refresh the form for the record in question, it was still marked as "Active" afterwords.  I realized, finally, that for some reason the refresh doesn't work.  Closing the form and reopening it will then display the proper value from the database and the user will then be able to see that the record is in fact set to "Inactive".

Tags:
Categories: C# | CRM