使用sdk将新用户添加到CRM 4.0

时间:2009-11-24 15:35:27

标签: dynamics-crm dynamics-crm-4

有没有人有示例代码使用sdk将新用户添加到CRM 4.0?

2 个答案:

答案 0 :(得分:2)

我有基于另一个系统中的用户为我们创建用户的代码,因此我无法将其全部粘贴到此处 - 大部分内容对您没有意义 - 但这是它的核心:

[在VB抱歉:-) - 同样在这里发布VB时我发现我需要使用'//'来表示注释以使格式正确]

Public Sub CreateNewUser()
  Dim s as mscrm.CrmService = GetMyService()
  Dim newUser as New mscrm.systemuser()
  With newUser
     .domainname = "domain\user"
     .firstname = "Stan"
     .lastname = "Molda"
     //set anything else you want here
  End With
  Dim userGuid as guid = s.Create(newUser)

  //Next we need to assign the user a role
  AssignRole(userGuid)

  //Finally we need to assign them to the correct Time Zone
  SetUserTimeZone(userGuid)
End Sub

Public Sub AssignRole(g as Guid)
    Dim s as mscrm.CrmService = GetMyService()
    Dim req As New mscrm.AssignUserRolesRoleRequest()
    req.UserId = g
    req.RoleIds = New Guid() {GetTheGuidForMyPrimaryRole()}
    s.Execute(req)
End Sub

Public Sub SetUserTimeZone(g as Guid)
    Dim s as mscrm.CrmService = GetMyService()
    Dim r As New mscrm4.RetrieveUserSettingsSystemUserRequest()
    r.ColumnSet = New mscrm3.AllColumns()
    r.EntityId = New Guid(g)
    Dim resp As mscrm.RetrieveUserSettingsSystemUserResponse = CType(s.Execute(r), mscrm.RetrieveUserSettingsSystemUserResponse)
    Dim settings As mscrm.usersettings = CType(resp.BusinessEntity, mscrm.usersettings)
    settings.timezonecode = New mscrm.CrmNumber
    settings.timezonecode.Value = OUR_TIME_ZONE_CONSTANT
    Dim update As New mscrm.UpdateUserSettingsSystemUserRequest()
    update.Settings = settings
    update.UserId = g
    s.Execute(update)
End Sub 

答案 1 :(得分:1)

对于C#,请查看我的问题Dynamics CRM: Create users with specific GUIDs,它完全符合您的要求(但不是完全我想要的内容:-P)。