Passing valuse from VBScript to InfoPath field

C

craigster76

I am trying to obtain the network username when an InfoPath form loads, then
assign that username to a field in the form. I have tried many different
variations of examples that I have found, but none have worked. Below is the
code I am using in the "Sub XDocument_OnLoad(eventObj)" event:

XDocument.DOM.selectSingleNode("field2").Text = objNet.UserName

Any ideas on how to pass the value of the username from the script to a
field on the form?

Craig
 
F

Franck Dauché

Hi Craig,

Once you get your objNet initialized (new ActiveXObject("WScript.Network"),
you need to assign you objNet.UserName to:
XDocument.DOM.SelectSingleNode(full XPath for the root to field2), not just
field2. Your path should look like: /my:rootName/my:......./my:field2".

Hope that helps.

Franck Dauché
 
C

craigster76

Franck,

Thank you for your assistance. I have tried using the full xpath, but still
am unsuccessful. The full xpath looks like this:

XDocument.DOM.selectSingleNode("/my:myFields/my:field2") = objNet.UserName

Is my xpath incorrect?

Craig
 
F

Franck Dauché

No, you are fine, but you need a ".text" before the = sign...

Franck Dauché
 
S

SDecou

I am receiving an error when I try to use ("WScript.Network") in Infopath
using VBScript. Have anyone been successful getting this to work? This is
what my code looks like:

Dim objNetwork
objNetwork = new ActiveXObject("WScript.network")
msgbox objNetwork

I am receiving an error and have tried using a SET statement which still
doesn't work.
 

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