Error when changing field value with selectSingleNode - InfoPath Dev
in

InfoPath Dev

Error when changing field value with selectSingleNode

Last post 03-03-2008 10:41 AM by Greg Collins. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-28-2008 03:36 PM

    • KoopLaFez
    • Not Ranked
      Male
    • Joined on 01-22-2008
    • San Diego, CA
    • Posts 21

    Error when changing field value with selectSingleNode

    I'm trying to change the value of a field using the selectSingleNode method.  I have a test form that I use to test and debug new code before I use it on my production form.  In the Test form, I used the following code to change the value of the "Test" field to "123":

    XDocument.DOM.selectSingleNode("my:myFields/my:Test").text = "123";

    This worked fine, but when I moved into my production form, I got the following error:

    Reference to undeclared namespace prefix: 'my'.

    I looked back through my code and I realized tha the namespace definition that was in my test form was not in my production form, so I added the following line of code at the top of the Script.js:

    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-01-22T18:18:32" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

    The next time I ran the code, I got the following error:

    'XDocument.DOM.selectSingleNode(...)' is null or not an object

     I don't know what to do at this point.  Any ideas?

     

  • 02-29-2008 09:26 AM In reply to

    Re: Error when changing field value with selectSingleNode

    Most likely the two forms have different namespace definitions for the "my" prefix. In your test form you have:

    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-01-22T18:18:32" 

    But in your production form, the date-time stamp on the end is likely different. The definition needs to match exactly what the form template says it should be. To find out, extract your form files and open the manifest.xsf or template.xml file in notepad and copy the valid definition for the "my" prefix. Then use the correct one in the code.

     

  • 02-29-2008 11:53 AM In reply to

    • KoopLaFez
    • Not Ranked
      Male
    • Joined on 01-22-2008
    • San Diego, CA
    • Posts 21

    Re: Error when changing field value with selectSingleNode

    It worked!  Thanks Greg.  I'm learning  this as I go, and it seem like the more I learn the more dangerous I get.

  • 03-03-2008 10:41 AM In reply to

    Re: Error when changing field value with selectSingleNode

    That's the way it is with computers!

    It can sometimes be like the new "computer mom" who discovers "format c:" :o)

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.