Event firing and repeating section - InfoPath Dev
in

InfoPath Dev

Event firing and repeating section

Last post 01-24-2006 12:51 PM by Matt Faus. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 01-16-2006 06:25 PM

    Event firing and repeating section

    Using VB.Net
    I query a SQL table to populate a repeating section.
    If a user changes a value in a dropdown listbox, I use OnAfterChange to
    change another value in the current record. That seems to work fine for only
    the first record.
    Also, when I run the query, the OnAfterChange fires many times as the
    query returns records.
    I want the OnAfterChange to only execute my code when a user changes a
    specific record and to act only on that record....


    added this code--query doesn't fail, but , after more testing, I found that
    if I changed the second record returned, it still didn't work.
    <InfoPathEventHandler(MatchPath:="/dfs:myFields/dfs:dataFields/d:Offload_Request/@LocationID", EventType:=InfoPathEventType.OnAfterChange)> _
    Public Sub Offload_Request_LocationID_attr_OnAfterChange(ByVal e As
    DataDOMEvent)
    ' Write code here to restore the global state.

    If (e.IsUndoRedo) then
    ' An undo or redo operation has occurred and the DOM is read-only.
    Return
    End If

    ' A field change has occurred and the DOM is writable. Write code here to
    respond
    ' to the changes.
    'If FacilityID changes, LocationOffloadCode should be changed to
    Null, so sproc can reassign correct code
    Dim myLocationOffloadCode As IXMLDOMNode

    If e.Operation = "Insert" Then
    Try
    myLocationOffloadCode =
    thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Offload_Request/@LocationOffloadCode")
    myLocationOffloadCode.text = Nothing
    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try
    End If
    End Sub
  • 01-17-2006 06:19 PM In reply to

    Re: Event firing and repeating section

    To select the field of the specific row, try something like this:

    e.Source.parentNode.selectSingleNode( "@LocationOffloadCode" );

    Depending on what e.Source points to you might have to "normalize" the source and use something more like this:

    e.Parent.selectSingleNode( "@LocationOffloadCode" );

    I hope this helps!

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-21-2006 04:53 PM In reply to

    Re: Event firing and repeating section

    If e.Operation = "Insert" Then
    Try
    is true when the SQL query returns data and also true when I choose a different value in the drop down listbox. So whatever action I take happens to every record returned.
    How do I differentiate between a query return and a user changing the value?
  • 01-23-2006 01:15 AM In reply to

    Re: Event firing and repeating section

    Hi Rick,
    Are you using an OnAfterChange event handler?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 01-23-2006 07:53 PM In reply to

    Re: Event firing and repeating section

    Yeah, my code is in the first message.
    OnAfterChange fires twice for each record returned from the query.
    I can use e.Operation = "Insert" to filter out half the firings, but I really need to filter out ALL the firings for the initial query return, and catch only one when the user changes the value.
  • 01-23-2006 09:26 PM In reply to

    Re: Event firing and repeating section

    Sorry for missing the code. What is causing the SQL query to run? You could set some state before and after that and filter on the state. The other thing you could do is disable updates during the SQL query to prevent DOM events but only do that if you are sure the resulting DOM will be valid.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 01-24-2006 09:27 AM In reply to

    Re: Event firing and repeating section

    Thanks, that worked perfectly.
    Now I just need to select the right row to change working..neither of the suggested code above worked, so I need to play around with it until it returns a value.
  • 01-24-2006 10:00 AM In reply to

    Re: Event firing and repeating section

    Looking in the debugger, both e.source.parentnode and e.parent resolve to 'nothing'
    I seem to be able only to get the value of the first record returned.
    So, neither of these suggestions are working..
    e.Source.parentNode.selectSingleNode( "@LocationOffloadCode" );
    Depending on what e.Source points to you might have to "normalize" the source and use something more like this:
    e.Parent.selectSingleNode( "@LocationOffloadCode" );
  • 01-24-2006 10:03 AM In reply to

    Re: Event firing and repeating section

    + Me {OffloadRequestReview.OffloadRequestReview} OffloadRequestReview.OffloadRequestReview
    - e {Microsoft.Office.Interop.InfoPath.SemiTrust.DataDOMEventWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DataDOMEvent
    + [Microsoft.Office.Interop.InfoPath.SemiTrust.DataDOMEventWrapper] {Microsoft.Office.Interop.InfoPath.SemiTrust.DataDOMEventWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DataDOMEventWrapper
    IsUndoRedo False Boolean
    MatchExpression "/dfs:myFields/dfs:dataFields/d:Offload_Request/@LocationID" String
    + NewValue "66" {String} Object
    + OldValue "73" {String} Object
    Operation "Insert" String
    + Parent {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    ReturnMessage Nothing String
    ReturnStatus True Boolean
    - Site {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + [Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper] {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper
    attributes Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNamedNodeMap
    baseName "LocationID" String
    + childNodes {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeList
    + dataType {System.DBNull} Object
    definition Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    - firstChild {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + [Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper] {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper
    attributes Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNamedNodeMap
    baseName Nothing String
    - childNodes {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeList
    - [Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper] {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper
    context <error: an exception of type: {System.InvalidCastException} occurred> Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    expr <error: an exception of type: {System.InvalidCastException} occurred> String
    Item <cannot view indexed property> Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    length 0 Integer
    + dataType {System.DBNull} Object
    definition Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    firstChild Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    lastChild Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    namespaceURI Nothing String
    nextSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    nodeName "#text" String
    nodeType NODE_TEXT Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeType
    + nodeTypedValue "66" {String} Object
    nodeTypeString "text" String
    + nodeValue "66" {String} Object
    + ownerDocument {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMDocument50Wrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument
    - parentNode {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + [Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper] {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper
    attributes Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNamedNodeMap
    baseName "LocationID" String
    + childNodes {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeListWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeList
    + dataType {System.DBNull} Object
    definition Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + firstChild {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + lastChild {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    namespaceURI Nothing String
    nextSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    nodeName "LocationID" String
    nodeType NODE_ATTRIBUTE Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeType
    + nodeTypedValue "66" {String} Object
    nodeTypeString "attribute" String
    + nodeValue "66" {String} Object
    + ownerDocument {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMDocument50Wrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument
    parentNode Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    parsed True Boolean
    prefix Nothing String
    previousSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    specified True Boolean
    text "66" String
    xml "LocationID="66"" String
    parsed True Boolean
    prefix Nothing String
    previousSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    specified True Boolean
    text "66" String
    xml "66" String
    + lastChild {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    namespaceURI Nothing String
    nextSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    nodeName "LocationID" String
    nodeType NODE_ATTRIBUTE Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeType
    + nodeTypedValue "66" {String} Object
    nodeTypeString "attribute" String
    + nodeValue "66" {String} Object
    + ownerDocument {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMDocument50Wrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument
    parentNode Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    parsed True Boolean
    prefix Nothing String
    previousSibling Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    specified True Boolean
    text "66" String
    xml "LocationID="66"" String
    + Source {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    + XDocument {Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.XDocument
    + myLocationID {Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper} Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
    myLocationOffloadCode Nothing Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode
  • 01-24-2006 11:32 AM In reply to

    Re: Event firing and repeating section

    this works
    myLocationOffloadCode = e.Parent.selectSingleNode("../@LocationOffloadCode")
    but it produces error msg for every other record returned.
    It does function correctly, as far as I can see--I set the LocationOffloadCode to Nothing, and only that record gets set.
    I can turn off the error message popup in the try statement and be functional..
    Doesn't feel good tho...
  • 01-24-2006 12:51 PM In reply to

    Re: Event firing and repeating section

    You might want to incorporate this function into your code. This is a function provided with common.js and ensures that your node is always normalized. It sounds like you need your node normalized every other record and not on the others.

    /*------------------------------------------------------------------------------
    normalizeSource() - Ensures that we always get a node of type NODE_ELEMENT
    or NODE_ATTRIBUTE.
    ------------------------------------------------------------------------------*/
    function normalizeSource(oEvent)
    {
    // Return the node's parent if the node is of type NODE_TEXT and its parent
    // is of type NODE_ELEMENT
    if (oEvent.Parent.nodeType == 1 && oEvent.Source.nodeType == 3)
    return oEvent.Parent;

    // Return the node if it is of type NODE_ELEMENT or NODE_ATTRIBUTE;
    if (oEvent.Source.nodeType == 1 || oEvent.Source.nodeType == 2)
    return oEvent.Source;
    }


    Glad to hear it's working at least a little now, good luck!

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.