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 ?