Records / Ifelse statements

silvenwolf
Member Posts: 7
Hi,
I'm fairly new to Navision Attain / C/Side code, and I'm having some difficulties.
When I run the following code, although there is more than 1 record which matches the criteria, it only brings back one record.
If "Payroll Ledger Entry"."Journal Batch Name" = 'OFFICE PR' then
"Payroll Ledger Entry".SETFILTER("Payroll Control Code",'%1|%2','OFFICE HOURS WORKED',
'HOUR SICK OFFICE')
Else
"Payroll Ledger Entry".SETFILTER("Payroll Control Code",'%1|%2','HOUR REG',
'HOUR SICK')
The user is supposed to enter in the Journal Batch name to either get records related to OFFICE PR or FIELD PR. Where am I going wrong? Please help. If I fail the If statement, then the else statement runs fine.
Help would be greatly appreciated, thanks.
-S.
I'm fairly new to Navision Attain / C/Side code, and I'm having some difficulties.
When I run the following code, although there is more than 1 record which matches the criteria, it only brings back one record.
If "Payroll Ledger Entry"."Journal Batch Name" = 'OFFICE PR' then
"Payroll Ledger Entry".SETFILTER("Payroll Control Code",'%1|%2','OFFICE HOURS WORKED',
'HOUR SICK OFFICE')
Else
"Payroll Ledger Entry".SETFILTER("Payroll Control Code",'%1|%2','HOUR REG',
'HOUR SICK')
The user is supposed to enter in the Journal Batch name to either get records related to OFFICE PR or FIELD PR. Where am I going wrong? Please help. If I fail the If statement, then the else statement runs fine.
Help would be greatly appreciated, thanks.
-S.

Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary
0
Comments
-
could you put more code than that part. There could be other filters you've set, and what do you mean it only brings back?0
-
Thanks for your prompt reply, so far.
Believe it or not, that's the only C/Side code I've got for that report.
The only other filters are:
Earned Pay Cycle Term - Year
Earned Pay Cycle Period - a number, ie 24.
They're all supposed to be user input.
1. I run the report
2. I enter in 'OFFICE PR' for Journal Batch Name and '24' for Pay Cycle Period
3. The report looks for the relevant records
4. Only one record appears on the report.
When I run the report, with Earned Pay Cycle Period = 24, and comment out the entire "else" section along with the If, I get more than one record.
-S.Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary0 -
where are you putting this code? on predata item? It won't work there because it will always run the else statement.
I think you should put the code onaftergetrecord this way
if "Payroll Ledger Entry"."Journal Batch Name" = 'OFFICE PR' then begin
if ("Payroll Ledger Entry".Payroll Control Code" = 'OFFICE HOURS ORKED') OR ("Payroll Ledger Entry".Payroll Control Code" = 'HOUR SICK OFFICE') then
Currreport.skip;
end else
if ("Payroll Ledger Entry"."Payroll Control Code" = 'HOUR REG') OR
("Payroll Ledger Entry"."Payroll Control Code" = 'HOUR SICK') then
Currreport.skip;0 -
if "Payroll Ledger Entry"."Journal Batch Name" = 'OFFICE PR' then begin if ("Payroll Ledger Entry".Payroll Control Code" = 'OFFICE HOURS ORKED') OR ("Payroll Ledger Entry".Payroll Control Code" = 'HOUR SICK OFFICE') then Currreport.skip; end else if ("Payroll Ledger Entry"."Payroll Control Code" = 'HOUR REG') OR ("Payroll Ledger Entry"."Payroll Control Code" = 'HOUR SICK') then Currreport.skip;
Mmmmm, I Love the smell of Fresh Code in the afternoon.. =P~
Sorry - I Think I need a vacation :?0 -
Ara3n: The only time it'll filter out the job codes is if I put it in the OnPreDataItem section. That, and it works fine except for the fact that it only returns one record (and doesn't return the other matching records to that criteria).
I just tried putting it in the OnAfterGetRecord section per your advice, and it doesn't work - I get every single job code in the report regardless of what I type in for Journal Batch Name.
Savatage: Try going to Europe and drinking up a storm. That'll relax ya.
Everyone else: any other ideas? It still isn't working, grumble.
-S.Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary0 -
Lets first check out if no other filters are on the record.
after your SETFILTER, putMESSAGE('Filters=%1\No. Of Records=%2', "Payroll Ledger Entry".GETFILTERS, "Payroll Ledger Entry".COUNT);
This shows the filters and the no. of records in it.
It is also possible that you have defined some filters in the "DataItemTableView"- or "DataItemLink"-properties.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
To be able to say more, I need to know structure of your report. Please, descibe the dataitems you are using (with indent level and possible linked fields between dataitems).0
-
I have only one DataItem, no links.
However, I did fix it - I put the code back in OnPreDataItem because in OnAfterGetRecord, it will always pull one wrong record in the report.
I also changed the filter to a Request Report checkmark field, and it definetly cleaned up really well.
Thanks for all your time guys (n' gals, if any).
-S.Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary0
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