简体   繁体   中英

dynamics crm 2013 c# plugin update/change system user timezone in it's usersettings

hello, i need to create a plugin to update a new user -timezone immediately after it created, but i don't know how to update the timezone in the connected usersettings - which attributes (like TimeZoneCode) do i must change if i always want to change to time zone to the my country- paris? , and how to update? **my steps:

  1. i create a post operation plugin, on systemuser entity - create
  2. get the id of the new systemuser // systemUser.systemuserid;
  3. retrieve its connected userSettings according to the systemuser id

ColumnSet attributes = new ColumnSet(new string[] { "timezonecode" }); var userSettingsResult = _service.Retrieve(userSettings.LogicalName, newSystemUserId, attributes);

**4. but i dont know which attributtes i need to update in usersettings to change the genereal time zone

for example: from london to my country paris ( i always change to paris)

do i only need to change the TimeZoneCode or i need to change more attributes like TimeZoneBias? and if so which attributes and and how?**

my code

public void updateNewUserTimeZone(MOHServiceContext myContext, Entity entity, ITracingService trc, IOrganizationService service, IPluginExecutionContext executionContext)
    {           
        if (entity != null)
        {
           // post operation - the new system user
            var systemUser = entity.ToEntity<systemuser>();
            var newSystemUserId=systemUser.systemuserid;  //get the id of the new systemuser

             if (newSystemUserId)
                {
                    //find the userSettingObject that has the same id as the system user now created

                    --var userSettingsResult = (from userSettingObject in myContext.userSettingsSet
                                        --where userSettingObject.systemuserid == newSystemUserId                                            
                                        --select userSettingObject).FirstOrDefault();

                // second way to retrive user setting
                //the fields we wandt to retrive from usersettings
                    ColumnSet attributes = new ColumnSet(new string[] { "timezonecode" }); 

                // Retrieve the usersettings and its timezonecode attribute.
                var userSettingsResult = _service.Retrieve(userSettings.LogicalName, newSystemUserId, attributes);                   




                    //if we find serSettingObject that has the same id as the system user now created
                    if (userSettingsResult != null)
                    {
                    //how to update the time zone in userSettingsResult we found to paris?

                    }
                }


            }

thanks a lot :) li

Get the TimeZoneIndex value and update the user settings TimeZoneCode with the corresponding value.

var userSettings = new UserSettings()
{
    Id = userSettingsId,
    TimeZoneCode = 105 //(GMT+01:00) Brussels, Copenhagen, Madrid, Paris
}; 
organizationService.Update(userSettings);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM