selectSingleNode Returns Null

T

Troy Zirk

I have not changed any of the defaults (e.g. - namespaces, code, etc.) in a
new form. i added a dropdown and renamed it "Branch" (case correct). i added
a button which, when clicked, tries to run this code:

var nodes = XDocument.DOM.selectSingleNode("/my:myFields/my:Branch");

for some reason this returns null. any ideas?

Troy
 
J

Jerry Thomas [MSFT]

I tried:
function CTRL2_5::OnClick(eventObj)
{
var nodes =
XDocument.DOM.selectSingleNode("/my:myFields/my:Branch");
XDocument.UI.Alert(nodes.text);
}
and it worked for me.
Can you try this?

--
Jerry Thomas
Microsoft Office InfoPath
---------------------------------------
This posting is provided "As Is" with no warranties, and confers no rights.
Use of any included script sample are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
 
S

Steve van Dongen [MSFT]


You are setting the SelectionNamespaces to the wrong namespace in
script.js. This line
XDocument.DOM.setProperty("SelectionNamespaces",

'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-06-21T20:52:12"');
should have the namespace found in the XSD file
XDocument.DOM.setProperty("SelectionNamespaces",

'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-07-13T21:26:23"');

Also, your code doesn't work because branch is an XML node object, not
a string. And in this case it will be better to use substring instead
of substr.

var branchNode =
XDocument.DOM.selectSingleNode("/my:myFields/my:Branch");
var branch = branchNode.text;
var branchID = branch.substring(
branch.indexOf("(") + 1,
branch.indexOf(")")
);

Regards,
Steve
 
T

Troy Zirk

Thanks Steve, that did the trick!! It must've been the incorrect namespace.
I suspected that but didn't know how to correct it. I appreciate your
assistance.

Troy
 

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