How to know who fill the form

S

S.Dayot

Hello I want to include in my form the name of the person who will fill the
form. But I don't know how to do it maybe use VBscript to have the username
of ActiveDirectory account if you can't help me please.
 
S

Scott L. Heim [MSFT]

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.
 
R

Radovan

Try this:

var oNet = new ActiveXObject("Wscript.Network");
sUserID = oNet.UserName;
 
P

Patrick Halstead [InfoPath MVP]

The problem with JScript is that it requires Full Trust to create the
ActiveXObject. Why bother?
You can use C# and System.UserName, or better yet, create an Active
Directory web service (like the one we sell for a measly $19.95 at
http://www.infopathdev.com/webstore/detail.aspx?itemid=18) to return the
data for you. That way, you can remain Domain Trust which is much less of a
pain.

Cheers,
Patrick Halstead
http://www.infopathdev.com/


Radovan said:
Try this:

var oNet = new ActiveXObject("Wscript.Network");
sUserID = oNet.UserName;
rights
 

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