Forum Discussion

Urmikhan's avatar
Urmikhan
Occasional Contributor
5 years ago
Solved

how i give iteration into my script to read from excel sheet multiple times

I used this syntax for to read data but i try to do multiple set of data to run my scripts(rather than keywords) multiple times.so What syntax I should use in to my scripts  to read different data an...
  • RUDOLF_BOTHMA's avatar
    5 years ago

    var test =(Driver.Value('Customer name)');
    DDT.CurrentDriver.Next();

     

    This always re-initiates the varable test.  That means it will only ever contain the last single value you were looking for.  Try something like this instead:

    var returnValue;
    while (! Driver.EOF()) 
    { 
    //Gets a value from the storage and posts it to the log
    returnValue += "; " + (Driver.Value('Customer name')); 
    DDT.CurrentDriver.Next(); 
    
    }
    ...
    return returnValue;

    This should return a list of all the values for a given field in a single string seperated by ";"

     

    That may not be what you are looking for, but it looks like the intent is to bring back ALL the records, rather than just the last record.  Consider making your function more generic:

     

    function testdata(filename,sheetname,fieldname){
    var Driver = DDT.ExcelDriver(filename, sheetname);
    var returnValue while(!Driver.EOF()){
    ...
    returnValue += "; " + Driver.Value(fieldname);
    ...
    }
    ... } function testone(){ var functionReturn = testdata("D:\\MyFile2.xlsx","Sheet1","Customer Name"); Log.Message(functionReturn); }

    That way it means you can re-use the function