Appendchild onload problem - InfoPath Dev
in

InfoPath Dev

Appendchild onload problem

Last post 01-11-2007 08:08 AM by shaun.nieves. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 01-04-2007 04:37 PM

    Appendchild onload problem

    Hi, I'm trying to load data into two repeating tables onload. The first one works fine but the second one bombs out on the second pass. Here is the error:


    System.NullReferenceException
    Object reference not set to an instance of an object.
    at InfoPathProject1.InfoPathProject1.State()
    at InfoPathProject1.InfoPathProject1.OnLoad(DocReturnEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)



    Here is my code:


    Sub Federal()
    'Start insert Federal waste codes**********************

    Dim dataDOM As DOMDocument50 = thisXDocument.DataObjects("FederalWasteCodes").DOM
    dataDOM.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-12T22-07-01"" ")
    Dim numRows As Integer = thisXDocument.GetDOM("FederalWasteCodes").selectNodes("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes").length()
    'MsgBox(numRows, MsgBoxStyle.Critical)

    Dim oParentNode As IXMLDOMNode
    oParentNode = thisXDocument.DOM.selectSingleNode("/my:myFields")
    Dim strFields As String
    strFields = "<my:CodeConcat xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-01T00:12:07'><my:Federal/></my:CodeConcat>"
    Dim domXMLNode As IXMLDOMDocument
    domXMLNode = thisXDocument.CreateDOM()

    domXMLNode.async = False
    domXMLNode.loadXML(strFields)

    Dim i As Integer

    For i = 1 To numRows
    Dim Code As String = thisXDocument.GetDOM("FederalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes[" & i & "]/@Code").text
    Dim sName As String = thisXDocument.GetDOM("FederalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:FederalWasteCodes[" & i & "]/@Short_name").text
    'MsgBox(Code, MsgBoxStyle.Critical)
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & i & "]/my:Federal").text = Code + ", " + sName
    If i <> numRows Then
    oParentNode.appendChild(domXMLNode.documentElement.cloneNode(True))
    Else
    End If
    Next

    'End insert Federal waste codes***************

    End Sub



    Sub State()
    'Start insert State waste codes****************
    Dim dataDOM2 As DOMDocument50 = thisXDocument.DataObjects("CalWasteCodes").DOM
    dataDOM2.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-12T22-07-01"" ")
    Dim numRows2 As Integer = thisXDocument.GetDOM("CalWasteCodes").selectNodes("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes").length()
    'MsgBox(numRows2, MsgBoxStyle.Critical)

    Dim oParentNode2 As IXMLDOMNode
    oParentNode2 = thisXDocument.DOM.selectSingleNode("/my:myFields")
    Dim strFields2 As String
    strFields2 = "<my:CodeConcat xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-01T00:12:07'><my:State/></my:CodeConcat>"
    Dim domXMLNode2 As IXMLDOMDocument
    domXMLNode2 = thisXDocument.CreateDOM()

    domXMLNode2.async = False
    domXMLNode2.loadXML(strFields2)

    Dim iState As Integer

    For iState = 1 To numRows2
    Dim Code2 As String = thisXDocument.GetDOM("CalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes[" & iState & "]/@Code").text
    'MsgBox(Code2, MsgBoxStyle.Critical)
    Dim sName2 As String = thisXDocument.GetDOM("CalWasteCodes").selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:CalWasteCodes[" & iState & "]/@Short_name").text
    'MsgBox(sName2, MsgBoxStyle.Critical)
    'MsgBox(iState, MsgBoxStyle.Critical)
    Dim node As String = thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text
    MsgBox(node, MsgBoxStyle.Critical)
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text = Code2 + ", " + sName2
    If iState <> numRows2 Then
    oParentNode2.appendChild(domXMLNode2.documentElement.cloneNode(True))
    Else
    End If

    Next

    'End insert State waste codes******************
    End Sub


    If anyone has any ideas I would greatly appreciate it. Thanks!
    Shaun Nieves
    Sharepoint Manager
  • 01-04-2007 10:30 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Appendchild onload problem

    Hi Shaun Nieves,

    Can you explain on which line you got the error? IF you debug it OnLoad it should display the line number for the error.
  • 01-05-2007 08:16 AM In reply to

    Re: Appendchild onload problem

    How do I step into the code? I entered in System.Diagnostics.Debugger.Break() at the beginning of the OnLoad proc however when I click preview, it does not break and the error comes up without telling me the line number.


    I should also mention that I don't think it's the code itself. If I flip the order of the repeating table creation, I get the same error. So both procedures work, it's just that they don't work when they are both executed onload. If I run one at a time, they work fine. I even tried moving them to their own procedures and calling them from the onload event but I get the same error.
    Shaun Nieves
    Sharepoint Manager
  • 01-05-2007 12:33 PM In reply to

    Re: Appendchild onload problem

    I'm thinking this is an infopath bug. I tried something a little different. I added the rows first and then tried to fill in the data but I got the same error. What I then did was add a button to the form that would fill in the
    value of the second row after it was created in the onload function and I get the same error but if I change the button to update a value in the first repeating table, it works just fine.
    Shaun Nieves
    Sharepoint Manager
  • 01-05-2007 12:35 PM In reply to

    Re: Appendchild onload problem

    Hi Shaun,

    I think I see your problem. and it's with these two lines:

    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & i & "]/my:Federal").text = Code + ", " + sName
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text = Code2 + ", " + sName2

    In both loops you are looping from 1 to N, but in the second loop you should be looping from N to 2N in that specific statement,
    so depending on the order maybe change it like this:

    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & i + numRows & "]/my:Federal").text = Code + ", " + sName
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState + numRows2 & "]/my:State").text = Code2 + ", " + sName2

    This is just a quick guess, it would be much easier if you gave smaller code chunks that were giving you an error. To do this,
    try commenting more and more of your code until it runs without error, and then you've found the error! Or you could switch
    to managed code which would be MUCH easier to work with! :) Good luck!
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-05-2007 01:13 PM In reply to

    Re: Appendchild onload problem

    Hey Matt thanks for the help. I'm using VB.net managed code. I'm not sure how that would work. i + numRows(which is 17) would be 18 and there wouldn't be a row 18.

    I've identified the problem line of code but it's bombing at the second iteration. The first row is created, the data is filled, the second row is created and when the below line of codes tries to insert the value, the code bombs. Again, I think it's a bug because I tried adding the rows first, then in an onclick event, tried to fill the rows but I get the same error. The only row that is recognizable is row 1. Every row after row 1 is unrecognizable.

    thisXDocument.DOM.selectSingleNode("/my:myFields/my:CodeConcat[" & iState & "]/my:State").text = Code2 + ", " + sName2

    Here is the error
    System.NullReferenceException
    Object reference not set to an instance of an object.
    at InfoPathProject1.InfoPathProject1.State()
    at InfoPathProject1.InfoPathProject1.OnLoad(DocReturnEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)


    My bet is that if you create two separate repeating tables at once, it bugs out the second table. What do you think?
    Shaun Nieves
    Sharepoint Manager
  • 01-11-2007 08:08 AM In reply to

    Re: Appendchild onload problem

    I really think this is a bug because if this is by design then something is terribly wrong.
    I am unable to create two repeating tables programatically even if the calls are separate.
    I have one procedure being called in an onafterchange event in one dropdown box and another
    procedure being called in an onafterchange event in a second dropdown. The first one fires without
    a hitch but the second one always bombs out with the same error. It doesn't matter which one I do
    first, the second one always bombs after the first row is inserted with the following error.

    System.NullReferenceException
    Object reference not set to an instance of an object.
    at InfoPathProject1.InfoPathProject1.State()
    at InfoPathProject1.InfoPathProject1.OnLoad(DocReturnEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)


    Does anyone have an idea or know how I can escalate to Microsoft?
    Shaun Nieves
    Sharepoint Manager
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.