1

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

4

2 回答 2

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 
于 2009-11-25T19:43:29.037 回答
1

对于 C#,看看我的问题Dynamics CRM: Create users with specific GUIDs,这正是你想要的(但不是想要的 :-P)。

于 2010-03-02T20:59:19.630 回答