Forum Discussion

RUDOLF_BOTHMA's avatar
RUDOLF_BOTHMA
Community Hero
6 years ago

Getting an empty string from a Table variable

Hi there.

 

I'm finding a challenge when trying to run (multiple) of my KWTs that call a script that iterates through a table variable.

as an example:

MyTableVariable:

Column: |ItemDescription|
Row 1 :  |My item's description|
Row 2    |[empty string]|

 

My script then iterates

 

Project.Variables.MyTableVariable.Iterator.Reset();
...
textbox.settext(Project.Variables.MyTableVariable.Iterator.Value("ItemDescription"));
...
Project.Variables.MyTableVariable.Iterator.Next();

 

 

This works for the first iteration, but fails for the second iteration, because the Value("") returns null on the second iteration, not an empty string.  To me it's important to distinguish between an empty string and null

 

Some validation is to check what happens if the textbox is blank, but other validation is to check what happens if the user doesn't input anything.  In other words, does the page load data correctly and would the user be able to save without moving to that textbox.  Currently I distinguish these actions by putting the string 'null' into my table variable when I want to action and intend to use the empty string if I want to blank the textbox.  Can't do that if the field in the table variable returns a null when I put in an empty string.

 

A hacked workaround would be to create the table variable

Column: |ItemDescription|
Row 1 :  |[empty string]| //this is going to be null
Row 2    |"EmptyString"| // this will literally be a piec of text "EmptyString"

Then have a function:

function TransformIterator(columncount, iterator)
{
  for(var i = 0;i<columncount;i++)
  {
    if(iterator.Value(i)==undefined || iterator.Value(i)==null || aqString.ToUpper(iterator.Value(i))=='NULL')
    {
      iterator.Value(i)=null;    
    }
    else if(aqString.ToUpper(iterator.Value(i))=='EMPTYSTRING')
    {
      iterator.Value(i) = '';      
    }
  }
}

then:

Project.Variables.MyTableVariable.Iterator.Reset();
...
TransformIterator(Project.Variables.MyTableVariable.ColumnCount,iterator);

if(Project.Variables.MyTableVariable.Iterator.Value("ItemDescription")!=null)
{
	textbox.settext(Project.Variables.MyTableVariable.Iterator.Value("ItemDescription"));
}
...
Project.Variables.MyTableVariable.Iterator.Next();

It's ugly though and depends on me always remembering to call the transform function.  Any thoughts of a better way ?

 

 

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    If I remember it correctly, the initial value of the string project variable and/or cell of the project variable of table type is null indeed.

    Null changes to the empty string after you assign and delete any value to the variable/cell and after that it is not possible to assign null again to the variable/cell from the UI.

     

    • RUDOLF_BOTHMA's avatar
      RUDOLF_BOTHMA
      Community Hero

      Null changes to the empty string after you assign and delete any value to the variable/cell and after that it is not possible to assign null again to the variable/cell from the UI.

       


      I'm quite OK with that.  In this particular instance I'm just reading from the table variable, so I won't be manipulating the data at all.  I would like to try and get away from magic stuff like typing in a predefined string into the table variable and calling a function each time I read with an iterator in all my scripts - and then forget to do it or call it in the wrong place.  (I've already run afoul of this today :smileytongue:).  The approach I outlined does do the job at the end of the day, so my post is more of a "Thoughts on a better way to do this?" I guess