SetStateAccount Message (CrmService)
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
| Works for all deployment types | Works online and offline |
Sets the state of an account.
The relevant classes are specified in the following table.
| Type | Class |
| Request | SetStateAccountRequest |
| Response | SetStateAccountResponse |
| Entity | account |
Remarks
To use this message, pass an instance of the SetStateAccountRequest class as the request parameter in the Execute method.
The possible states are defined in the AccountState enumeration. To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see SetState Privileges.
This message updates the account entity properties statuscode and statecode.
Example
The following code example shows how to use the SetStateAccount message.
Example
[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
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 = 2;
// 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);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim create As New CreateRequest()
create.Target = targetCreate
Dim created As CreateResponse = CType(service.Execute(create), CreateResponse)
' Create the request object.
Dim state As New SetStateAccountRequest()
' Set the properties of the request object.
state.AccountState = AccountState.Inactive
state.AccountStatus = 2
' EntityId is the GUID of the account whose state is being changed.
state.EntityId = New Guid("AD618DB2-F0DB-4A6A-8C4B-2F2213EAA38E");;
' Execute the request.
Dim stateSet As SetStateAccountResponse = CType(service.Execute(state), SetStateAccountResponse)
See Also
Concepts
Reference
© 2010 Microsoft Corporation. All rights reserved.

