Please someone help with getting Username infomation

P

Paul B

Hi

I am using infopath SP1. I have a tet field called "name" All i want to do
is get the user name of the current user into this text field. I am also
using Portal.

I have read a lot of posts and still have no idea how to do this. I really
dont want to have to install any more software as the form needs to be
accessed by a lot of users.

Thanks
 
S

Scott L. Heim [MSFT]

Hi Paul,

I have a question: are you attempting to get the "logged on user" name
(i.e. from Active Directory?)

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Philip Colmer

Paul B said:
Hi

I am using infopath SP1. I have a tet field called "name" All i want to do
is get the user name of the current user into this text field. I am also
using Portal.

I have read a lot of posts and still have no idea how to do this. I really
dont want to have to install any more software as the form needs to be
accessed by a lot of users.

Thanks

You can use scripting - Environment.UserName will get you the account name.
However, that isn't necessarily the same as the user's name. If you actually
want their name, it does start to get harder. You've got at least two
choices:

1. Get the InfoPath form to query Active Directory so that it can extract
the user's name based on the account name you get from Environment.UserName.

2. Use a web service. The InfoPath form calls the web service which then
queries Active Directory and returns the information you want.

3. Use the web service in SharePoint Portal Server. SharePoint supports a
"GetUserProfileByName" web service. More details at
http://msdn.microsoft.com/library/en-us/spptsdk/html/mUserProfileServiceGetUserProfileByName.asp

The advantage of (1) is that all of the code is self-contained in the form.
The BIG disadvantage is that in order to make the queries to AD, you have to
make the form fully trusted which is a real pain, although it is not too bad
if you've got certificates and you can code-sign the form.

The advantage of (2) is that the InfoPath form runs normally and doesn't
need to be fully trusted. The disadvantage is that you've got to set up a
web server so that you can run the web service.

The advantage of (3) is that you don't need to write the web service but you
do need to have profiles set up in SharePoint Portal Server.

I can provide some code for (2) if needed.

--Philip
 
P

Paul B

Hi

Thanks for the response. Could you please provide me with the code you have
offered so i can play with it.

Also can a form be fully trusted without having to purchase anything and if
so do you have the code to extract the username.

Thanks

Paul
 
P

Philip Colmer

Paul B said:
Hi

Thanks for the response. Could you please provide me with the code you
have
offered so i can play with it.

Please send your email address to philip dot colmer at proquest dot co dot
uk and I'll send it to you.
Also can a form be fully trusted without having to purchase anything and
if
so do you have the code to extract the username.

If you use a web service, the form doesn't need to be fully trusted. It only
has to be fully trusted if you perform the AD lookups within the form. If
you want to do that, the easiest way I've found to make the form work is to
sign it with a code-signing certificate. If you've got a PKI infrastructure,
you can issue one from there. If you haven't, you can buy one.

--Philip
 
S

Scott L. Heim [MSFT]

Hi Paul,

Not sure if you have what you need yet but here is some VB Script code to
gather information regarding the logged on user...please note - this 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

Stop
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

In a sample I use, I simply call this on the forms Load event to populate a
text box:

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

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

I hope this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Andrew Couch

Philip,

Am I missing something trying to use Environment.UserName?

My code is:
function XDocument::OnLoad(eventObj)
{
var userName = Environment.UserName;
XDocument.UI.Alert(userName);
initializeNodeValue("/my:myFields/my:completedBy", userName);
}

I just get the error "Environment is undefined" when I try and preview the
form. I tried System.Environment.UserName, but then I get "System is
undefined".

Cheers
Andrew
 

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