'Find' code on Form acting erratically

Mauddib
Mauddib Member Posts: 269
Hi guys,

I have a small problem that I will put in terms of the sales line table to help explain it. Picture The normal sales order form with header and lines. In the ONVALIDATE() trigger for "No." of the Sales Line FORM I have the following code. I have also tried it on the sales line TABLE onvalidate() for "No." with the same problem:

//Ensure item isnt already on order. IF it is JUMP To the existing item.
LRecSoLine.RESET; //LRecSoLine - Record of sales line table.
LRecSoLine.SETCURRENTKEY("Document No.", "No.");
LRecSoLine.SETRANGE("Document No.", "Document No.");
LRecSoLine.SETRANGE("No.", "No.");
LRecSoLine.SETFILTER("Line No.", '<>%1', Rec."Line No.");
IF (LRecSoLine.FIND('-')) THEN BEGIN
Rec := LRecSoLine;
Rec.FIND;
EXIT;
END ELSE BEGIN
IF INSERT THEN;
END;

Now picture an order of 10 lines all with different items. You go to the END of this list to insert a new line and you enter an existing item and it jumps to the line containing the existing item. Wonderful!!!

However... if you go into the middle of the 10 lines and hit F3 to insert a line then do the same thing it does NOT jump to the existing Item's line.

Thoughts??? I have Currform.UPDATE(FALSE) in the onaftervalidate() too.

Comments

  • DenSter
    DenSter Member Posts: 8,307
    One thing to take into consideration is to never write code like that on the form. This type of validation code belongs in the table. I would create a new form for order entry that does this type of thing, or have an entry area on the header part.
  • Mauddib
    Mauddib Member Posts: 269
    Ok I put it on the form because for some reason I'd convinced myself it wouldnt work on the Table. I have put the same code on the table now but the same unusual behaviour is occurring.

    As for creating a new form or using the header to do the work I am afraid due to the requirements of the project this is not an option.
  • lubost
    lubost Member Posts: 633
    Some notes to your code:
    1. You have to add "Document Type" filter
    2. You have to add "Type" filter
    3. Never use INSERT in this table explicitly

    I hope it helps you
  • Mbad
    Mbad Member Posts: 344
    And you are sure what you are doing cant be resolved simply by changing the key on the prints?
  • Mauddib
    Mauddib Member Posts: 269
    Thanks lubost but I was just using the sales line table as an example because everyone understands this table. The problem happens on this table JUST like on my own table.

    The table where I am ACTUALLY having the same problem doesnt have document type, type or any problems with INSERT.

    However if I can find out why is it happening on the sales lines, i will also know why it is happening on my own table.