Friday, April 26, 2013

How to retrieve user time zone in MSCRM 2011

Following is the piece of code that could be used to retrieve the user's timezone code.



 private Entity GetUserTimeZone(IOrganizationService service, Guid userId)

        {

            try

            {

 

                RetrieveUserSettingsSystemUserRequest request = new RetrieveUserSettingsSystemUserRequest();

                request.ColumnSet = new ColumnSet("timezonecode");

                request.EntityId = userId;

                RetrieveUserSettingsSystemUserResponse response = (RetrieveUserSettingsSystemUserResponse)service.Execute(request);

                return response.Entity;

            }

            catch (FaultException<OrganizationServiceFault>)

            {

                throw;

            }

            catch (Exception)

            {

                throw;

            }

        }

No comments: