English 中文(简体)
Adding a new user to CRM 4.0 using sdk
原标题:

Does anyone have sample code to add a new user to CRM 4.0 using sdk?

问题回答

I have code that creates users for us based on users in another system so I can t exactly paste it all here - most of it wouldn t make sense to you - but this is the core of it:

[In VB sorry :-) - also when posting VB here I find I need to use // to indicate a comment to make the formatting correct]

Public Sub CreateNewUser()
  Dim s as mscrm.CrmService = GetMyService()
  Dim newUser as New mscrm.systemuser()
  With newUser
     .domainname = "domainuser"
     .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 

For C#, take a look at my question, Dynamics CRM: Create users with specific GUIDs, which does exactly what you want (but not exactly what I want :-P).





相关问题
The given key was not present in the dictionary

I am trying to make a simple plugin for MS Dynamics CRM 4.0 where send data of a salesorder in a SOAP message on the update of the order. The strange thing is that I get this error every other time i ...

Creating a PDF of a Dynamics CRM 4.0 report programmatically

We are currently in the midst of upgrading our CRM 3.0 installation to CRM 4.0. One of the things we were doing from our external web site is pulling a PDF of a report using the ReportViewer control ...

"required field EntityId is missing" error

No matter what i attempt i keep getting the following exception being thrown by MSCRM 4.0 Invalid format of input XML for request SetStateITG_glcode: required field EntityId is missing here is ...

热门标签