Filter a report based on values from a variable

MorilenMorilen Member Posts: 30
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.

Comments

  • matttraxmatttrax Member Posts: 2,309
    So after the code you already have:

    IF CustomerInfo."Credit Type Code" <> 'X' THEN
    CurrReport.SKIP;
  • MorilenMorilen Member Posts: 30
    That works awesome, thank you. For the single value it ran with no trouble.

    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:
  • SPost29SPost29 Member Posts: 148
    You were soooooo close!
    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
  • matttraxmatttrax Member Posts: 2,309
    Morilen wrote:
    IF Customerinfo."Credit Type Code" <> '5' OR Customerinfo."Credit Type Code" <> '5P' THEN
    CurrReport.SKIP;

    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
  • matttraxmatttrax Member Posts: 2,309
    Another way is

    IF NOT Customerinfo."Credit Type" IN THEN
  • MorilenMorilen Member Posts: 30
    Yeah I see it now that you showed me. 8)

    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.
  • rsaritzkyrsaritzky Member Posts: 469
    Use of AND and OR logic can be confusing until you understand the rules. I actually learned the rules of logic in a college class in the Philosophy department. Most Philosophy programs have courses in logic. There I learned that:

    NOT (A or B) = (NOT a) and (NOT b )

    also things like

    A or B (but not both A and B) = NOT(A and B)

    In C/AL coding, also remember to put parens around each complete expression that evaluates to TRUE or FALSE
    Ron
Sign In or Register to comment.