Code assistance needed - for environment variable assignment - ple

  • Thread starter Programmer - wannaB
  • Start date
P

Programmer - wannaB

How do I set the default of an InfoPath field to be the current USERNAME.

This form is for use in-house on all XP WS's and I would like to just pull
in the local environment variable is USERNAME.
 
H

Henning Krause [MVP - Exchange]

Hello,

if you are using managed code, you can use Environment.Username. This will
give you the logon name of the user. If you want the displayname, you must
make a query to Active Directory.

Greetings,
Henning Krause
MVP - Exchange
http://www.infinitec.de
 
P

Programmer - wannaB

Thank you...

I am sorry I did not explain this very well... let me try again..

I have already attached a SQL Stored Procedure as a secondary data source,
and my intent is to use the Environ.Username to retrieve the Fullname from
the secondary data source.

But some of what I have read here makes me think that it might be just as
easy to pull the fullname from an active directory query.

All that aside, can anyone provide me an example of the code needed to
retrieve the Environment.Username into a variable that can be asigned to an
InfoPath field ??

Just occured to me but I am thinking >>
VAR defaultfield = Environment.username

something like that ???? or I am way off...
 
S

Scott L. Heim [MSFT]

Hi,

Assuming you have VS.NET, then once you have the "UserName" stored in a
variable, you would need something like the following to get to the field
on your InfoPath form:

** NOTE: This assumes you simply placed a text box on your form named
field1 and you want to fill this on the Load event of the form:

Dim objField1 As IXMLDOMNode
objField1 =
thisXDocument.DOM.selectSingleNode("//my:myFields/my:field1")

objField1.text = Environment.UserName

I hope this helps!

Scott L. Heim
Microsoft Developer Support

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

Programmer - wannaB

OH, That looks like it should work. and I do have access to VS.NET But I am
not very well versed in it.

One more question, Can you recomend any good books that can explain
statements such as these that you provided;
Dim objField1 As IXMLDOMNode
objField1 =
thisXDocument.DOM.selectSingleNode("//my:myFields/my:field1")
objField1.text = Environment.UserName
Things such as how is IXMLDOMNode used, what does it mean ???

Thank you very much for all your help.
 
S

Scott L. Heim [MSFT]

Hi,

Unfortunately I don't know of specific books that would be of interest;
however, this is really programming with "XML" so you may wan to look in
that arena specifically.

In addition, the VS.NET help file has some in-depth information as well.

Lastly, if you would prefer to use script (VB or J) to get the logged on
user name, let me know as I have a sample routine for this as well.

Best regards,

Scott L. Heim
Microsoft Developer Support

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

Programmer - wannaB

Thank you again.....

Yes, I think that I read InfoPath uses both windows and VB script as past of
it's base install, so that there's nothing additional needed to run those.
SO, Yes I would love to see anything else you have. I also find it
interesting to compare how the same thign can be done in different languages,
even when I am not very knowledgeable in those languages...

Again, thank you for all your time, it really is greatly appreciated...
 
S

Scott L. Heim [MSFT]

Hi,

The following is a VBScript example of querying Active Directory - this
will require your form to have "full trust:"

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 of using this, I have a text box on my form named "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

Good luck!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no 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