Set a value in the XML using Script

B

Brad Simon

I have to be making this much more difficult than it is.

When I save the document, I need to save a value on a field (ie:
my:myFields/Group/FieldName). It is a text field, and I simply cannot make
it work. I have tried the XPath a number of different ways. I am using
VBscript (since I know it far better than JavaScript).

I am deeply disappointed in the Script editor provided with InfoPath, and
the pain it is to do a simple debug. I am pulling my hair out, and I don't
have any left. I wouldn't use it, if I had a choice.

Isn't there a simple "SaveThisValueTo(my:myFields/Group/FieldName,
"myValue")? If not, what do I have to do to make this work.
 
B

Brad Simon

HA! I was right, there is a simple way, here it is:

XDocument.DOM.selectSingleNode("/my:myFields/my:Group/my:FieldName").text =
"myValue"

BTW: The script editor is still not good, and it was not apparent that this
is what i needed to do. I saw another post (yes, I did look BEFORE I posted
this one), and saw something similar to what I needed to do.
 
A

Andrew Watt [MVP - InfoPath]

Brad,

Do you need to set the value only when saving the form??

If not, then you could use a rule in the second form control. If it's
a text box simply set the default value of the (read-only) text box to
be the value in the field whose value you want to match.

That would work for simple cases, anyway.

Andrew Watt
MVP - InfoPath
 

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