I need to filter a report using code, and base it on a variable I have included.
Now I have tried the Setfilter command about 100 different ways and places and nothing seems to work. Every time, like clockwork, it displays everything.
I am using Nav 5.0.
I have a Report based solely on the Sales Invocie Header table.
I have a global variable "Customerinfo" which is a record based on the customer table.
I have a field on the report with a source expression of: Customerinfo."Credit Type Code".
I have the following code listed under OnAfterGetRecord():
IF "Sell-to Customer No." = '' THEN
CLEAR(Customerinfo)
ELSE
Customerinfo.GET("Sell-to Customer No.");
This currently links my data together and populates the Credit Type Code value from the Customer card onto my Sales Invoice Report. What I cannot get it to do is limit the report to only customers that have a certain Credit Type Code.
The code I have tried to use for a filter is: Customerinfo.Setfilter ("Credit Type Code", '5P'). I actually need it to filter in only records which are Credit Type Code, '5' or '5P', but I was trying to get it to work at all first with one. Obviously I am doing something wrong, but I can't find a lick of information on how this might work from any source. I have scoured sites and books and this just doesn't seem to be covered.
Any help would be greatly appreciated.
0
Comments
IF CustomerInfo."Credit Type Code" <> 'X' THEN
CurrReport.SKIP;
My Blog - nav.education
Attempted to add in the other value I need and it is giving me a:
Type conversion not possible because 1 of the operators contains and invalid type.
Tried:
IF Customerinfo."Credit Type Code" <> '5' OR '5P' THEN
CurrReport.SKIP;
And
IF Customerinfo."Credit Type Code" <> '5' OR Customerinfo."Credit Type Code" <> '5P' THEN
CurrReport.SKIP;
Then
IF Customerinfo."Credit Type Code" <> '5'|'5P' THEN
CurrReport.SKIP;
Which just returned a syntax error.
Also (Even though I didn't for a second think it would work)
IF Customerinfo."Credit Type Code" <> '5' THEN
CurrReport.SKIP;
IF Customerinfo."Credit Type Code" <> '5P' THEN
CurrReport.SKIP;
and it didn't, hehe.
With the last shred of my dignity, I tried
IF Customerinfo."Credit Type Code" <> '5' OR <> '5P' THEN
CurrReport.SKIP;
And
IF Customerinfo."Credit Type Code" <> '5' | <> '5P' THEN
CurrReport.SKIP;
Which returned the same errors as with previous attempts for their respective operators.
I'm sure it is something simple. :?
What am I missing? :oops:
Any time you write an if statement with two or more comparisons
you need to put each comparison in paranthesis
If a = 5 or a=7 then
etc.
Needs to be
If (a = 5) or (a=7) then
etc.
It needs to resolve each expression first into a true or false value and then decide whether the whole expression is valid
Steve
So close here. Run through it with sample data.
Say you have Credit Type = '1'. 1 <> 5 so it skips it.
Say you have Credit Type = '5'. 5 <> 5P so it skips it.
Say you have Credit Type = '5P'. 5P <> 5 so it skips it.
This way skips everything! You need
IF Customerinfo."Credit Type Code" <> '5' AND Customerinfo."Credit Type Code" <> '5P' THEN
My Blog - nav.education
IF NOT Customerinfo."Credit Type" IN THEN
My Blog - nav.education
I was thinking of the OR as an, If this condition OR this condition, like an either this or that. The AND worked great.
Thank you everyone for the help, its all good now.
NOT (A or = (NOT a) and (NOT b )
also things like
A or B (but not both A and = NOT(A and
In C/AL coding, also remember to put parens around each complete expression that evaluates to TRUE or FALSE