How to set status of an built in entity like Account or custom entity to inactive?
Below is the code sample for SetState/Status to inactive for a system entity...[C#]
// Standard CRM Service Setup
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the request object.
SetStateAccountRequest state = new SetStateAccountRequest();
// Set the properties of the request object.
state.AccountState = AccountState.Inactive;
state.AccountStatus = -1;
// EntityId is the GUID of the account whose state is being changed.
state.EntityId = new Guid("AD618DB2-F0DB-4A6A-8C4B-2F2213EAA38E");;
// Execute the request.
SetStateAccountResponse stateSet = (SetStateAccountResponse)service.Execute(state);
If you want to set the status/state to a dynamic entity then use the following -
SetStateDynamicEntityRequest req = new SetStateDynamicEntityRequest();
req.Entity = new Property();
//Primary key of record
req.Entity.Id = new Guid("{AAD5DA71-34E3-DB11-90D0-0003FF873FE6}");
req.Entity.Name = "new_customentity";
req.State = "inactive";
req.Status = -1;
//req.State = "active";
//req.Status = 1;
service.Execute(req);
you have to use these provided classes to get the status inactive for a particular record in CRM. You cannot use StatusCode and StateCode to set these values directly to the entity as it did not reflected to me on the UI grid. However, Execute did wrk. Thanks - Dipesh
No comments:
Post a Comment