Subscribe Bookmark RSS Feed

How to deal with "no table" case in functions, that return table reference?

miguello

Community Trekker

Joined:

Jan 27, 2016

I'm debugging my app. Here's a question.

 

 

When I press a button, I get something done on a data table, which I pull\construct in a separate function:

 

pressButton=Function({this},
myTable = getMyTableFunction(input1, input2);

//Do Stuff with myTable


);

Function getMyTableFunction returns a reference to a datatable that was pulled and handled inside the function. But sometimes data pull does not produce any results. For this case I just have a simple if that, when table has data, manipulates it and returns table reference, otherwise opens a modal window that says no data was pulled and that's it.

 

What happens: myTable is not defined then (function does not return anything). And when I proceed doing stuff with table I get errors.

What I want: Understand what I should put in if statement for return. Some like return(Empty Table) or something.

So that when myTable = GetMyTableFunction() is evaluated, I can check myTable and refuse to try to do any manipulations with it.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

You can always use a Try() function like:

If( Try( myTable << Get Name, "No Table Returned" ) != "No Table Returned",
....
)
Jim
2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

You can always use a Try() function like:

If( Try( myTable << Get Name, "No Table Returned" ) != "No Table Returned",
....
)
Jim
miguello

Community Trekker

Joined:

Jan 27, 2016

Yes! I was using this a lot inside the function, but for some reason was fixed on using something else outside. Currently I just decided to not close the empty table so that there is reference passed from the function, and instead raise a flag that gets evaluated outside of the function, and, if raised, does not do any further actions and closes empty table.