简体   繁体   English

Dynamics CRM 2013 C#插件的用户设置中的更新/更改系统用户时区

[英]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? 您好,我需要创建一个插件来在创建新用户后立即更新-timezone,但是我不知道如何在连接的用户设置中更新时区-如果我一直想要更改哪些属性(如TimeZoneCode)将时区更改为我的国家/地区巴黎? , and how to update? ,以及如何更新? **my steps: **我的步骤:

  1. i create a post operation plugin, on systemuser entity - create 我在systemuser实体上创建了一个后期操作插件-创建
  2. get the id of the new systemuser // systemUser.systemuserid; 获取新的系统用户的ID // systemUser.systemuserid;
  3. retrieve its connected userSettings according to the systemuser id 根据系统用户ID检索其连接的userSettings

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

**4. ** 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? 我只需要更改TimeZoneCode还是需要更改更多属性,例如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 非常感谢:) li

Get the TimeZoneIndex value and update the user settings TimeZoneCode with the corresponding value. 获取TimeZoneIndex值,并使用相应的值更新用户设置TimeZoneCode

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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