Hi,
If you have created an InfoPath solution using Visual Studio.NET then you
can use the "Environment.UserName" variable. If you simply need to be able
to query Active Directory, then here is a sample procedure to do so:
** NOTE: This uses VBScript and will require your form to be fully trusted.
Function GetADInfo
Dim objADSystemInfo
Dim objUser
Dim objManager
Dim strLogin
Dim strMail
Dim strAlias
Dim objGroup
Dim strGroups
Set objADSystemInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" + objADSystemInfo.UserName)
Set objManager = GetObject("LDAP://" + objUser.Get("manager"))
'Get all the groups the user is enrolled in
'For Each objGroup In objUser.Groups
' strGroups = strGroups & vbcrlf & objGroup.name
'Next
strLogin = objUser.Get("cn")
strMail = objUser.Get("mail")
strAlias = left(strMail, instr(1, strMail, "@")-1)
'XDocument.UI.Alert "User: " & strLogin & vbcrlf & "Alias: " & strAlias &
vbcrlf & "Manager: " & objManager.Get("name") & _
'vbcrlf & "E-mail: " & strMail
GetADInfo = strAlias
End Function
What you can now do is use code similar to the following to populate a text
box on your form when it opens - so you would have code like this on the
Load event of the form:
Dim objUser
Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1")
If objUser.Text = "" Then
objUser.Text = GetADInfo
End If
Lastly, if you cannot have a fully trusted form then your last resort would
be to create a "WhoAmI" web service to get the user name - you can search
this forum for more information on this option.
I hope one of these is of benefit for you!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.