Unable to loop through a data list. - InfoPath Dev
in

InfoPath Dev

Unable to loop through a data list.

Last post 05-02-2005 01:37 PM by RichardM. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-29-2005 09:46 AM

    Unable to loop through a data list.

    I am a Lotus Notes developer trying to recreate database functionality in InfoPath. Who said that you can not teach an old dog new tricks?

    The Lotus Notes database is used to track sales orders and I created several scripts to parse through the records to calculate many different values. These scripts take the resulting calculations and create a report record for management purposes. I have replicated the same tracking form layout in InfoPath and I save the form data to a SQL database. This all works great and I can retrieve the data by using various queries and use different views to display the results.

    The problem is that I am unable to parse through the data and perform the calculations so a report can be created for management. I have found many examples on how to do this but they do not work for me.

    The process that I am going through to create the report:
    Step 1: Open form to a basic menu view that allows for the selection of the quarter and year
    Step 2: Query the adapter and retrieve the SQL Query command
    Step 3: Modify the SQL Query command based upon the selection made in step 1
    Step 4: Query the adapter using the new SQL Query command
    Step 5: Determine how many items are in the data list
    Step 6: Loop through the data list and calculate the different fields as required.
    Step 7: Enter these calculations into a report view.

    This all sounds very simple but I can not get past step 6.

    Using the below code causes a runtime error stating that “Object required”:

    var nodeList = dom.selectNodes("/dfs:myFields/dfs:dataFields/d:dtOrderTracking");
    var listLength = nodeList.length;
    var total = 0;

    for (var i=1; i<listLength; i++) {
    total = dom.documentElement.selectSingleNode("dfs:dataFields/d:dtOrderTracking/@OrderVal").value; //it is the in this line that causes the error
    XDocument.UI.Alert(total); // used to display the value of the field
    }

    If I modify the code by replacing the with a number it works OK.

    var nodeList = dom.selectNodes("/dfs:myFields/dfs:dataFields/d:dtOrderTracking");
    var listLength = nodeList.length;
    var total = 0;

    for (var i=1; i<listLength; i++) {
    total = dom.documentElement.selectSingleNode("dfs:dataFields/d:dtOrderTracking[1]/@OrderVal").value; //returns the value of the first entry
    XDocument.UI.Alert(total); // used to display the value of the field
    }

    I know that I am looping through the list because I can place a UI.Alert looking a i and it increments.

    Any assistance would really be appreciated.

    Thanks,
    Richard
  • 04-30-2005 08:10 AM In reply to

    Re: Unable to loop through a data list.

    Hi Richard, Welcome to the board.
    You made a small mistake in the following statement
    total = dom.documentElement.selectSingleNode("dfs:dataFields/d:dtOrderTracking/@OrderVal").value; //it is the in this line that causes the error

    You are placing "i" in between the string as part of the string, but value of "i" should go in place of "i". So your statement should be

    total = dom.documentElement.selectSingleNode("dfs:dataFields/d:dtOrderTracking["+i+"]/@OrderVal").value;

    But there is another best way that you can follow here, you already getting reference to the "d:dtOrderTracking" nodes in
    "var nodeList = dom.selectNodes("/dfs:myFields/dfs:dataFields/d:dtOrderTracking");"

    you can use this reference instead of selecting the whole node again. so your for loop can be
    for (var i=1; i<listLength; i++) {
    total = nodeList.selectSingleNode("@OrderVal").value;
    XDocument.UI.Alert(total);
    }

    Hope this helps!

    Agni
    InfoPathDev India
  • 05-02-2005 01:37 PM In reply to

    Re: Unable to loop through a data list.

    Agni,

    EXCELLENT!

    Your other reference suggestion worked exactly like I wanted it to.

    Thanks for your assistance.

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