3 Replies Latest reply: Nov 22, 2012 4:15 AM by 834498 RSS

    How to iterate virtual users using sql table response instead of databank

    946716
      I init database in the initialize and query the SQL database to get a table.

      I want to iterate the run method to read each row and do some webservice calls according to information from the SQL table.

      Whats the easiest way to achieve this. (Currently i do a "while" statement and loop over all the rows from the table object.)
        • 1. Re: How to iterate virtual users using sql table response instead of databank
          834498
          Hello
          You should "iterate" your script, not "run" it. (button just on the right side of the run button).
          This is exactly the purpose, to only iterate the run section.
          But maybe this is not what you are trying to achieve.
          In that case, pls let me know.
          Cheers
          JB
          • 2. Re: How to iterate virtual users using sql table response instead of databank
            946716
            Jean,

            Yes, I do want to iterate and not run my script.

            What i had done previously is create a databank (.csv) and have the run method to iterate over the records using the getNextDatabankRecord().

            But now in this particular case,
            I do not have a databank, but i do have a Table object that is returned as a result of a sql query in the initialize section.

            so as a workaround (not knowing how to use the iterator to iterate over this table object), i do the following.

            public Table table1;

            public void initialize() throws Exception {
            table1=utilities
                      .getSQLService()
                      .query("<some sql query>");

            }

            public void run() throws Exception {
                      
            for (int i=0; i<table1.getRowCount(); i++) {
            // do webservice calls using and validate results


            }
            }

            Now my question is how do i iterate over the table object that i get in the initialize section instead of having the "for" loop, which completely beats the iterate functionality.
            • 3. Re: How to iterate virtual users using sql table response instead of databank
              834498
              I understood :)

              You can directly use a variable call "iterationnum"

              getVariables().set("Iter_num", "{{@iterationnum}}",Variables.Scope.GLOBAL);
              String myInt = eval("{{Iter_num}}");

              // and then tranform the variable to a int.



              You can delete the for loop.

              JB