Validation Script Issue; Can you help? - InfoPath Dev
in

InfoPath Dev

Validation Script Issue; Can you help?

Last post 02-06-2007 04:12 PM by Matt Faus. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 02-06-2007 09:21 AM

    • tch_hp
    • Not Ranked
    • Joined on 02-06-2007
    • Posts 3

    Validation Script Issue; Can you help?

    I am trying to write a script in the OnAfterChange event for a text box that will change the value of a boolean atribute to true; that attribute is linked to a checkbox on the form. The schema string element for the text box is called "Overview" and the boolean attribute on that element is called "OverviewUpdate". Any ideas?
  • 02-06-2007 09:54 AM In reply to

    Re: Validation Script Issue; Can you help?

    Hi tch_hp and welcome to the forums!

    This should be pretty trivial, try this statement:

    thisXDocument.DOM.selectSingleNode( "/my:myFields/my:OverviewUpdate" ).text = "true";

    You'll have to update the XPath to match your schema exactly, but this should do the trick.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-06-2007 10:28 AM In reply to

    • tch_hp
    • Not Ranked
    • Joined on 02-06-2007
    • Posts 3

    Re: Validation Script Issue; Can you help?

    Ok, here's the code I used:

    XDocument.DOM.selectSingleNode("/xs:Overview/xs:OverviewUpdate").text="true";

    but I get a runtime error -

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

    ????
  • 02-06-2007 10:36 AM In reply to

    Re: Validation Script Issue; Can you help?

    Something is wrong with the XPath. You should double-check that it's correct and then see if you're hitting a namespace issue.

    http://infopathdev.com/howto/tutorials/default.aspx?i=ed2cf0c5895f468995cdd081cf17fead
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-06-2007 10:55 AM In reply to

    • tch_hp
    • Not Ranked
    • Joined on 02-06-2007
    • Posts 3

    Re: Validation Script Issue; Can you help?

    I don't see why it won't work. Here is the complete script code:

    /*
    * This file contains functions for data validation and form-level events.
    * Because the functions are referenced in the form definition (.xsf) file,
    * it is recommended that you do not modify the name of the function,
    * or the name and number of arguments.
    *
    */

    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xs="http://www.w3.org/2001/XMLSchema"');
    //</namespacesDefinition>


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    // This function is associated with the following field or group (XPath): /Track_Changes/Overview
    // Note: Information in this comment is not updated after the function handler is created.
    //=======
    function msoxd__Overview::OnAfterChange(eventObj)
    {
    var xmlOverviewUpdate = XDocument.DOM.documentElement.selectSingleNode("/xs:Overview/xs:OverviewUpdate");
    xmlOverviewUpdate.value = "true";

    // Write code here to restore the global state.

    if (eventObj.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond to the changes.

    }


    And here is the complete schema code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSpy v2006 sp2 U http://www.altova.com) by Tim Hansen (HP) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Track_Changes">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Overview">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="OverviewUpdate" type="xs:boolean" use="optional" default="false"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
  • 02-06-2007 04:12 PM In reply to

    Re: Validation Script Issue; Can you help?

    Hi tch_hp,

    I'm not going to be able to do full debugging for you, but you might try spitting out something like "XDocument.DOM.documentElement.xml" into a XDocument.UI.Alert();
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.