cancel
Showing results for 
Search instead for 
Did you mean: 

Getting an empty string from a Table variable

Highlighted
Contributor

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
Community Hero

Re: Getting an empty string from a Table variable

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.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Contributor

Re: Getting an empty string from a Table variable


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 Smiley Tongue).  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

Share Your Stories
Read Latest News
Top Kudoed Authors