How to Update the Status of System User

By | September 3, 2011

This is the code I’ve used in one of my unit tests where I had to test if an opportunity would be automatically re-assigned to another user if its owner was disabled.

See the code below:

    /// <summary>
    /// Updates the state of the CRM user.
    /// Use the SystemUserState enum to set the status.
    /// </summary>
    /// <param name=”userId”></param>
    /// <param name=”state”></param>
    private void UpdateSystemUserState(Guid userId, SystemUserState state)
    {
      Guid newContactId = Guid.Empty;
      SetStateSystemUserRequest setStateSystemUserRequest = null;
      SetStateSystemUserResponse setStateSystemUserResponse = null;
 
      setStateSystemUserRequest = new SetStateSystemUserRequest();
      setStateSystemUserRequest.SystemUserState = state;
      setStateSystemUserRequest.SystemUserStatus = -1;
      setStateSystemUserRequest.EntityId = userId;
 
      setStateSystemUserResponse = (SetStateSystemUserResponse)crmService.Execute(setStateSystemUserRequest);
 
    }

Leave a Reply