GreatNews
GreatNews

Reputation: 645

PowerBuilder - Error with SetFilter(string) - Expression is not valid

I have an application that generates some reports. I use some filters in data that is retrieved.

wf_gen_filtro_conceptos()

//PROBLEM---------------
dw_rp1.setfilter(string(is_filtro) + " " + "or IsNull(causa)")
//----------------------
dw_rp1.filter()
dw_rp1.sort()
dw_rp1.groupcalc()

In wf_gen_filtro_conceptos() the variable is_filtro is set up. The problem is when I use setfilter(). I can't concatenate those strings to create the new filter. If I use one of those strings, for example, IsNull(causa) on its own, there's NO problem.

Upvotes: 0

Views: 2619

Answers (4)

GreatNews
GreatNews

Reputation: 645

Thanks everyone for answering my question. I've tried the stuff you suggested but it's still throwing the same error..

Here is the function that set the filter up.

choose case  is_filtro_ca
case  ''
    messagebox("Filtro", "Is filter 1")
is_filtro = ""

case '*'
    messagebox("Filtro", "Is filter 2")
is_filtro = ""

case else
    messagebox("Filtro", "Is filter 3")
is_filtro = "causa in (" + is_filtro_ca + ")"

End choose

This function is called when a button "Show empty lines" is pressed. I put those messages an it always prints "Is filter 2".

Upvotes: 0

Roland Smith
Roland Smith

Reputation: 970

If you are combining different filter clauses you need an and between them.

Upvotes: 0

Eric Glenn
Eric Glenn

Reputation: 399

I suspect that is_filtro has an invalid column, or an invalid value, or is_filtro is null, or is_filtro is empty.


Initialize is_filtro to something meaningful.

This works if you want all values.

is_filtro = "(1 = 1)"

If is_filtro is empty ("")

dw_rp1.setfilter(string(is_filtro) + " " + "or IsNull(causa)")

setfilter would be effectively

dw_rp1.setfilter(" or IsNull(causa)")

If is_filtro is null

setfilter would be effectively

dw_rp1.setfilter()

Your filter needs to match the column datatype.

Suppose that causa is a string column and you intend to filter values A, B, and C.

Wrong

is_filtro = "causa in (A, B, C)"

Right

is_filtro = "causa in ('A', 'B', 'C')"

Upvotes: 2

Matt Balent
Matt Balent

Reputation: 2397

Add a line to concatenate the string before you use the SetFilter method. Something like

ls_filterstring = is_filtro + " " + "or IsNull(causa)"
dw_rp1.setfilter(ls_filterstring)

This way you can examine what is happening with your filterstring in the debugger. If is_filtro is NULL then the entire string will be NULL.

If is_filtro is being set make sure the quote marks, if any, in the string are correct.

Upvotes: 3

Related Questions