Records / Ifelse statements

silvenwolfsilvenwolf Member Posts: 7
edited 2006-01-06 in Navision Attain
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. :lol:
Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary

Comments

  • ara3nara3n Member Posts: 9,256
    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?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • silvenwolfsilvenwolf Member Posts: 7
    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. :D
    Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary
  • ara3nara3n Member Posts: 9,256
    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;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • SavatageSavatage Member Posts: 7,142
    edited 2006-01-05
    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 :?
  • silvenwolfsilvenwolf Member Posts: 7
    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. :lol:
    Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary
  • krikikriki Member, Moderator Posts: 9,112
    Lets first check out if no other filters are on the record.
    after your SETFILTER, put
    MESSAGE('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!


  • kinekine Member Posts: 12,562
    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).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • silvenwolfsilvenwolf Member Posts: 7
    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. :lol:
    Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary
Sign In or Register to comment.