Need to find "most recent" record in PO table for

johnsogjjohnsogj Member Posts: 103
Hello, I'm running a report that displays all items and related information for each. One column must display the cost from the most recent PO. I tried the following code:

POTable.SETRANGE("No.",Item."No."); to find the records in the PO table that match the current item on the report

IF POTable.FINDLAST THEN my logic here was that the last record would be the most recent

RecentVendor:= POTable."Buy-from Vendor No."

ELSE POTableHistory.SETRANGE("No.",Item."No."); if no record could be found in the PO table, it should go look in the PO Inv. Line table

IF POTableHistory.FINDLAST THEN

RecentVendor:= POTableHistory."Buy-from Vendor No."

ELSE RecentVendor:= 'N/A';

it doesnt seem to be working. any ideas?[/i]

Comments

  • idiotidiot Member Posts: 651
    IF it's your exact code I see some syntax error.
    What do you mean by not working?
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • johnsogjjohnsogj Member Posts: 103
    the report works fine only if the current item is NOT in the PO Line table and it has to go look in the Purchase Inv. Line table. (or it may not even be there so it displays "N/A". But whenever it comes to an item where there IS a record in the PO line table, it doesnt display the correct value. Instead, it just copies the value from the line above.

    here is my exact code:

    POTable.SETRANGE("No.",Item."No.");
    IF POTable.FINDLAST THEN
    RecentVendor:= POTable."Buy-from Vendor No."
    ELSE POTableHistory.SETRANGE("No.",Item."No.");
    IF POTableHistory.FINDLAST THEN
    RecentVendor:= POTableHistory."Buy-from Vendor No."
    ELSE RecentVendor:= 'N/A';
  • idiotidiot Member Posts: 651
    Sorry brain not working so maybe this lousy code will work

    RecentVendor:= 'N/A';
    POTable.SETRANGE("No.",Item."No.");
    IF POTable.FINDLAST THEN
    RecentVendor:=POTable."Buy-from Vendor No."

    IF RecentVendor='N/A' THEN
    POTableHistory.SETRANGE("No.",Item."No.");
    IF POTableHistory.FINDLAST THEN
    RecentVendor:= POTableHistory."Buy-from Vendor No."
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • welanderwelander Member Posts: 20
    you ned some begins and ends in your IF statements right now it will always get the result from the PO historie and never from the PO try this

    POTable.SETRANGE("No.",Item."No.");
    IF POTable.FINDLAST THEN
    RecentVendor:= POTable."Buy-from Vendor No."
    ELSE BEGIN
    POTableHistory.SETRANGE("No.",Item."No.");
    IF POTableHistory.FINDLAST THEN
    RecentVendor:= POTableHistory."Buy-from Vendor No."
    ELSE RecentVendor:= 'N/A';
    END;

    Best Regards Lars
  • johnsogjjohnsogj Member Posts: 103
    thank you! It worked perfectly
Sign In or Register to comment.