Filter a report based on values from a variable

Morilen
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.
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
-
So after the code you already have:
IF CustomerInfo."Credit Type Code" <> 'X' THEN
CurrReport.SKIP;0 -
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:0 -
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
Steve0 -
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' THEN0 -
-
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.0 -
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= (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 FALSERon0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions