Forum Discussion

pkroon's avatar
pkroon
Occasional Contributor
15 years ago

Data-Driven Loop from DBTable Reload Values

My basic issue is that I have 2 work tables (MS SQL Server) I want to use to drive a sales order entry application.  The first will have customer records, and the second will be updated on the fly with item information for each customer.  I have a script step that prepares the first table, and then a data-driven loop over this table for all of the customers.  This portion works fine.  Then, for each customer, I have another script step to prepare the second table, and then have a nested data-driven loop over this second table.



I originally made this all in a single keyword test, and it starts ok, but the inner loop never reloads its values after the first run.  Even though the table is updated with the script step, the DBTable variable is not reloaded.  To attempt to work around this, I created a separate keyword test that would run my main test.  This "wrapper" test has the outer loop, and this loop has 2 steps; the first is to update the table for the inner loop, and then second is to run my main keyword test.  My hope was that this inner loop would refresh at each separate running of the keyword test, but it still seems to only use the first set of records it gets, even though I can see the table being updated.



Is there any easier way to accomplish what I am trying to do?  Thanks.

6 Replies

  • Hi,


    You can call the Reset method of the DBTable variable used in your inner loop. Insert an operation which will do this on each iteration of your outer loop before the inner loop starts.

  • pkroon's avatar
    pkroon
    Occasional Contributor
    I added in a Call Object Method to call the Reset method on my DBTable variable, but it doesn't seem like that makes it reload its values.  It seems like it would just put the iterator back on the first row, but this is already done when the inner loop is run a second time in the second iteration of the outer loop.  It just goes to the first row on the same resultset, without reloading the resultset from the database.  Just to check that I added it in correctly, I attached another screenshot of this new step.
  • Hi,



    Data in DB Table variables is static, and it is not reloaded when it is changed in the source. See the Variables of the DB Table Type help topic.



    To avoid this, you can use DDT in scripts and reconnect to the data source (create a new driver) when the source is modified.

  • pkroon's avatar
    pkroon
    Occasional Contributor
    Can you give me an example, or point me to a help document, on how to have a script step that will load the values of a MS SQL table into a variable I can use in a data-driven loop?  I've seen some of how it works, but I'm not sure how to make the connection between the database and getting the values I pull back in a script to the data-driven loop.
  • Hi,



    You need to use DDT drivers. Write a script which will connect to your DB and iterate through its records. Each time the DB table changes its values, close the current driver and create a new one. You can find an example in the Using DDT Drivers help topic.
  • pkroon's avatar
    pkroon
    Occasional Contributor
    Thanks again for the help, I finally got this all working.  I used DDT.ADODriver and a While loop instead of the data-driven loop, and I have it working correctly now.  In case anyone else has a similar question, I did this with 2 functions in a script (to connect and to get the values).  I call the connect, then I run a While loop on a boolean variable that is controlled by my script, then I call the function to get the values at each iteration.  I pretty much followed the built-in examples, and split them out to different functions.  I attached the script I used in case it's of any value to anyone else.