Infopath and Active Directory

S

smonczka

Is it posible to pull a users information into an Infopath form from
active directory. If so could you point me in the direction of an KB
that would explain the process?

Thanks for the help,
Steve
 
A

agni

Hi Steve,
You have top either write a webservice to get the information from the
Active Directory or you can write code to get the infomation. But the
writing code will require full trust to your form.

Webservice is the best option for you. There is a Ready to use AD Webservice
to get the user info at www.autonomysystems.com premium downloads section.

-Agni
 
J

JNL

Hi Steve I paste you here a previous post of Steve its formaly help me hope
that it would be the same for you.


Yes - the following is sample VBScript:

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

As an example, I have a field on my form (field1) and on the Load event of
the form, I have the following:

Dim objUser
Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1")

If objUser.Text = "" Then
objUser.Text = GetADInfo
End If

So if field1 is blank, it calls the AD code and populates the text box with
the user's name.

My apologies as I did not intend for this to be confusing. The function
(GetADInfo) is simply pasted into the script editor behind your InfoPath
solution:

- From the Tools menu choose Programming and then select Microsoft Script
Editor
- Scroll to the bottom of all code and paste the function

- The second part of what I provided was merely to describe how that
function could be used. One way I have used this was to place this code:

Dim objUser
Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1")

If objUser.Text = "" Then
objUser.Text = GetADInfo
End If

In the "Load" event of the form (Tools->Programming->On Load Event.) Keep
in mind, this is just a sample and assumes there is a field on the form
named: field1 that resides in the myFields layer. So this sample code first
checks to see if "field1" is empty and if so calls the GetADInfo function
to populate that field.

There is one additional item I forgot to mention: this code will require
your form to be fully trusted. If you would like to get more information on
fully trusted forms, take a look at the following:

Deploy a Fully Trusted Form to a SharePoint Form Library
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkDeployURNFormToSharePoint_HV01086376.asp

Understanding Fully Trusted Forms
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkUnderstandingFullyTrustedForms.asp

Using the Form Registration Tool
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkUsingTheFormRegistrationTool.asp

I hope this helps!

Scott L. Heim
Microsoft Developer Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top