InfoPath 2003 and Active Directory

Posted on 2009-02-16
Last Modified: 2013-11-11

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.  


Question by:MartePalmer
    LVL 28

    Expert Comment

    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.

    Accepted Solution

    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
        Const ADS_SCOPE_SUBTREE = 2
        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


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
    Before you can digitally sign infopath forms, you must have a digital certificate. Microsoft Certificate Services will need to be enabled on a Windows Server 2008 to facilitate the creation and verification of the digital certifciates on the web ser…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now