Options

How to get the first record from the filtered varaiable?

pawanppawanp Member Posts: 90
IF ItemVendor.FIND('-') THEN REPEAT

Items.SETFILTER(Items."No." ,ItemVendor."Item No.");
ItemsTemp := Items;
ItemsTemp.INSERT;
UNTIL ItemVendor.NEXT = 0;


ItemsTemp := Items; always returns the first record from the table?? Please help

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,098
    Try this:
    IF ItemVendor.FIND('-') THEN 
      REPEAT
        Items.GET(ItemVendor."Item No.");
        ItemsTemp := Items;
        ItemsTemp.INSERT;
      UNTIL ItemVendor.NEXT = 0;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    kinekine Member Posts: 12,562
    Of course, you set the filter, but never did any FINDFIRST, FIND('-')...

    1) you are using SETFILTER but only with two parameters. It is Better to use SETRANGE in this situation (or if you want to use SETFITLER, than Items.SETFILTER(Items."No." ,'%1',ItemVendor."Item No.");)
    2) because you know the primary key of the record, much, much better is to use GET (Items.GET(ItemVendor."Item No.")). You do not need to filter and you have what you need in your variable...

    And as I see, Kriki was faster...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    SLF25SLF25 Member Posts: 37
    Your ItemsTemp is most probably an Item rec variable set to temporary. I don't advise that kind of use in a team of rookie developers, because someone who is programming by trying is going to try to fix a problem removing temporary property from record, and since this is a temporary table you have a .deleteall somwhere in your code. Oops. Some other programmer might want to try to validate this and that from the table, that is also not what you want.
  • Options
    BeliasBelias Member Posts: 2,998
    SLF25 wrote:
    ...try to fix a problem removing temporary property from record, and since this is a temporary table you have a .deleteall somwhere in your code. Oops.
    this is how i solve this kind of "errors": :wink:
    RRCheckEmpty.GETTABLE(TBItemTemp);
    IF NOT RRCheckEmpty.ISTEMPORARY THEN
      ERROR('TBItemTemp variable must be temporary!!!');
    TBItemTemp.DELETEALL;
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    matttraxmatttrax Member Posts: 2,309
    Belias wrote:
    this is how i solve this kind of "errors": :wink:
    Code: Select all
    RRCheckEmpty.GETTABLE(TBItemTemp);
    IF NOT RRCheckEmpty.ISTEMPORARY THEN
    ERROR('TBItemTemp variable must be temporary!!!');
    TBItemTemp.DELETEALL;

    Great stuff. =D> Maybe add to the Tips and Tricks section if it is not already there.
  • Options
    BeliasBelias Member Posts: 2,998
    matttrax wrote:
    Belias wrote:
    this is how i solve this kind of "errors": :wink:
    Code: Select all
    RRCheckEmpty.GETTABLE(TBItemTemp);
    IF NOT RRCheckEmpty.ISTEMPORARY THEN
    ERROR('TBItemTemp variable must be temporary!!!');
    TBItemTemp.DELETEALL;

    Great stuff. =D> Maybe add to the Tips and Tricks section if it is not already there.
    why not...the problem is that it's a bit of pain to declare recordref variables and error texts everytime...i thought about a way to do it in a codeunit, but we have the same old problem that we cannot pass a general table to a function :(
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.