InfoPath 2003 and Active Directory


Is there a way to use InfoPath to find a first and last name from Active Directory given a user ID?  I have tried the GetUserProfile service from SharePoint but I have not been able to get the attributes needed except for the person completing the form.

I need to be able to allow a user to enter a LAN ID and then get the last and first names associated with the ID.  I am open to using wither AD or GetUersProfile but all I have been able to find is information about the person completing the form.  


Who is Participating?
MartePalmerAuthor Commented:
I found the code my modifying some scripts from microsoft and applying through a OnChageAfter script.  So how would i have it execute for every new record in a table?  Any ideas?

Here is the code
Sub msoxd_my_Prefix_OnAfterChange(eventObj)
    empid = XDocument.DOM.selectSingleNode("//my:Prefix").Text
    On Error Resume Next
    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    Set oCommand =   CreateObject("ADODB.Command")
    oConnection.Provider = "ADsDSOObject"
    oConnection.Open "Active Directory Provider"
    Set oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.Get("defaultNamingContext") & _
      ">;(&(objectCategory=User)(sAMAccountName=" & empid & "));givenname, & _
      sn, department;subtree"
    Set oRecordSet = oCommand.Execute
    XDocument.DOM.selectSingleNode("//my:FirstName").Text = oRecordSet.fields("givenname")
    XDocument.DOM.selectSingleNode("//my:LastName").Text = oRecordSet.fields("sn")
    XDocument.DOM.selectSingleNode("//my:UnitCode").Text = left(oRecordSet.fields("department"), 5)
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
If eventObj.IsUndoRedo Then
	Exit Sub
End If
End Sub

Open in new window

Clay FoxDirector of Business IntegrationCommented:
I think an AD web service is the best method.

You can ID the form user.

Query all of their AD attributes such as email, Manager, department, etc.

Also you can then query other users too.

There are several around, I have used the one from

You also then do not need any code or anything to use them.  The only trick is that you need a server to host the webservice. Another benefit, over local lookups, is that this works on VPN and remote connections since it is using their domain credentials not local ones.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.