Tuesday, September 22, 2009

Update/ Set AccountStateInfo in CRM 4.0 / 3.0

private bool UpdateAccountState(Guid accid, string astatuscode, string astatecode)
{
bool checkflag = false;
try
{
CrmService Crm4_service = connect();
// Create the request object.
SetStateAccountRequest state = new SetStateAccountRequest();

// Set the properties of the request object.
if (astatecode == "Inactive")
{
state.AccountState = AccountState.Inactive;
}
if (astatecode == "Active")
{
state.AccountState = AccountState.Active;
}
state.AccountStatus = Convert.ToInt32(astatuscode);

// EntityId is the GUID of the account whose state is being changed.
state.EntityId = accid;

// Execute the request.
SetStateAccountResponse stateSet = (SetStateAccountResponse)Crm4_service.Execute(state);
checkflag = true;
}
catch
{
return checkflag;
}
return checkflag;
}