Monday, 13 April 2015

Get Current User Setting Timezone CRM C#

Sometimes we need to get the current user timezone, so here is the code:

public int? RetrieveCurrentUsersTimeZoneSettings(IOrganizationService service)
     var currentUserSettings = service.RetrieveMultiple(
     new QueryExpression("usersettings")
        ColumnSet = new ColumnSet("localeid", "timezonecode"),
        Criteria = new FilterExpression
            Conditions =
            new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)
     return (int?)currentUserSettings.Attributes["timezonecode"];

*You just need to pass the current CRM Service
Hope this helps.



My Name is..