selectSingleNode for all records in data source - InfoPath Dev
in

InfoPath Dev

selectSingleNode for all records in data source

Last post 07-27-2008 10:06 PM by PJagger. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-27-2008 12:47 AM

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 40

    selectSingleNode for all records in data source

    Hi

    I want to get the value of a field for all records in a repeating table. In my current repeating table there are 3 records.

    I use the following code to try to retrieve the value of the field for each record but it only ever gets the value of the 1st record in the repeating table:

    var Records = XDocument.DOM.selectNodes("/my:myFields/my:Itemisations/my:ItemisationsTable");

    for (var i=0; i < Records.length; i++)

    {

    var blah = Records[i].selectSingleNode("/my:myFields/my:Itemisations/my:ItemisationsTable/my:AllocationDetails/my:PaymentMethod");

    //note that the below I have used for debugging to verify the value of the field..... 

    //FileObject.Write(blah.text + "\t");

     }

    What am I doing wrong here? It is only ever showing the field value of the 1st record in the repeating table???

  • 07-27-2008 06:41 AM In reply to

    Re: selectSingleNode for all records in data source

    For "blah" you are iterating through all the records nodes and then going back up to your main node to select the value -- which always returns the first value. The selectSingleNode for that variable should be from Records[i], so: "my:AllocationDetails/my:PaymentMethod"
    Hilary Stoupa

  • 07-27-2008 04:00 PM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 40

    Re: selectSingleNode for all records in data source

    Hi Hilary

    Thanks for your reply.  I still need further directions.  What do you mean by so: "my:AllocationDetails/my:PaymentMethod"?

    Appreciate your help

    Phil

  • 07-27-2008 04:59 PM In reply to

    Re: selectSingleNode for all records in data source

    Oh, sure. I mean the code above should read thus:

    var Records = XDocument.DOM.selectNodes("/my:myFields/my:Itemisations/my:ItemisationsTable");

    for (var i=0; i < Records.length; i++)

    {

    var blah = Records[i].selectSingleNode("my:AllocationDetails/my:PaymentMethod");

    //note that the below I have used for debugging to verify the value of the field..... 

    //FileObject.Write(blah.text + "\t");

     }

    Because, you see, your variable called Records refers to the ItemisationsTable node. So, as you iterate through, you want to be setting your new variable to the PaymentMethod node that belongs to the record node you are currently looking at....

    Hilary Stoupa

  • 07-27-2008 06:00 PM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 40

    Re: selectSingleNode for all records in data source

    Okay Hilary,

    Tried your suggestion, at first it was not writing anything, however, I replaced [i] in the var blah line with 0 then 1 and yes it was writing the selected row accordingly.  I changed it back to [i] and its working!??  Thank you big time!

    I am hampered by my next step however,  I am trying to write a row of fields from a repeating table separated by tabs ("\t") and then start a new line ("\r" + "\n") before the next row of data is written and so forth  In others words, a tab delimited text file output.  I can't seem to enable my var blah to include the tab and another field.

    Please advise.

    Regards - Phil

  • 07-27-2008 09:29 PM In reply to

    Re: selectSingleNode for all records in data source

    Try doing this: 

    var Records = XDocument.DOM.selectNodes

    ("/my:myFields/my:Itemisations/my:ItemisationsTable");

     

    for (var i=0; i < Records.length; i++) {  FileObject.Write(Records[i].selectSingleNode("my:AllocationDetails/my:PaymentMethod").text + "\t");

     

    //…then repeat this for all the other fields except the last one …..

     

    //..then for the last one ensure you put the newline characters instead of the tab:

     

    FileObject.Write(Records[i].selectSingleNode("my:AllocationDetails/my:YourLastField").text + "\r” + “\n”);

     }

     

     

  • 07-27-2008 10:06 PM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 40

    Re: selectSingleNode for all records in data source

    Hey Josh,

    That did it! Thank you!  & Thank you Hilary!  You have both helped me enormously!

    Regards - Phil

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