Programmatically read all nodes in List Box - InfoPath Dev
in

InfoPath Dev

Programmatically read all nodes in List Box

Last post 02-24-2009 06:58 AM by Petronomicon. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-18-2009 09:03 AM

    Programmatically read all nodes in List Box

    Hello,

    It seems like this issue should be easy.  I'm simply trying to read the list box elements in my InfoPath form script.

    I set the following variable but I only retrieve the first value or the selected value.

    I'm not getting an error, just not reading through all of the elements of the list box.

    var xIncentives_A = XDocument.DOM.selectNodes("/my:myFields/my:Incentives[my:Incentives_Apvr != ' ']");

    var itemTotalNode = null;

    var sendTos = "";

    xIncentives_A.reset();

    while (itemTotalNode = xIncentives_A.nextNode()) {

      var nItemTotal = itemTotalNode.nodeTypedValue; XDocument.UI.Alert(nItemTotal);

     sendTos += nItemTotal;

     }

    I am completely stuck.  Thanks for your help.

     

     

    :o)
  • 02-18-2009 04:38 PM In reply to

    Re: Programmatically read all nodes in List Box

    What are you using as the data source for the values in the list box?  Are they values you manually entered in the form designer?  In InfoPath the value of a node bound to a list box is the value of the selected values.  Since it is an input control I'm sure you will agree that this does make sense.

    If you want to also have access to all the values in the list box, I would suggest making an XML file with the values you want and using that as a secondary data source to populate the list box.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-19-2009 06:27 AM In reply to

    Re: Programmatically read all nodes in List Box

    Thanks Jimmy!

    The values are stored in a SharePoint list, and I'm using a secondary data connection to populate the field when the form opens.  I was going to use it as a list to populate an email but can only access one element.

     I understand what you are saying, and I did see that there were some tips on the internet about accessing it through XML, but have never done that, although I'm game to try.

    Could you post the code, or point me to a resource?  Or if you have a better way to read values into a form from a SharePoint list, then have them available programmatically, that would be great.

    (I ended up using a repeatable table and using "cloneNode" to display the values, but I was trying to find a way that didn't require so much coding.)

    Thanks again for your help!!

    Dave

    :o)
  • 02-19-2009 07:36 AM In reply to

    Re: Programmatically read all nodes in List Box

    If the listbox is already being populated from the SharePoint list, then there is no need to add any extra XML.  The data is already there.  You just need to have your code access the values from your secondary data connection instead of the ListBox's bound node.  If you're unsure how to do this I can show you sometime tomorrow (it's already late here in Japan).

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-19-2009 07:39 AM In reply to

    Re: Programmatically read all nodes in List Box

    Thanks again!

    Yeah, I can get at the data programmatically so it's no big deal.  I was just hoping I could cut down on the amount of code.

    Thanks for your response!

    Get some sleep and have a great tomorrow!

    :o)
  • 02-19-2009 08:57 PM In reply to

    Re: Programmatically read all nodes in List Box

    Hello again,

     I'm not entirely clear on what you're trying to do.  If you're just trying to access a bunch of values in code, then getting at them in a secondary data source should not be all that more complicated than accessing it in the main data source; really just the code you have up there with a few lines changed and a few extra.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-24-2009 06:58 AM In reply to

    Re: Programmatically read all nodes in List Box

    Hi Jimmy.

    Sorry for the delay - hope your still following this thread.  In a nutshell:

    I have data in a SharePoint list I want to make available in my infopath form.  Data can easily be brought into the list box from SharePoint.

    I was hoping to be able to access the data in the list box through the DOM, but I can only read 1 element - whichever element is selected from the InfoPath screen. (An aside, I did see somewhere where you can read the elements using XML but that is new to me). Your statement that a list box is an Output and not input makes sense in this matter.

    So I changed the InfoPath script to go after the Secondary Data Source programmatically and read the elements from the SharePoint list into a repeating table structure using the 'cloneNode' method.

    This is OK, but I was hoping to use the list box to cut down on the whole cloneNode/parent/child coding thing.  I have it working now but thanks for your help.

    Dave

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