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)
        }
        }
     }).Entities[0].ToEntity<Entity>();
     return (int?)currentUserSettings.Attributes["timezonecode"];
}


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

Thanks.

2 comments:

My Name is..