Filtering on non-existing value in Primary Key issue

igor.chladiligor.chladil Member Posts: 28
Hello,

The following issue occurs in standard NAV DBs in versions 5SP1 as well as 4SP3.

1. We are experiencing the behaviour where the following action causes an error:
we filter on the non-existing value of the Primary Key resulting in the non-editable form [only some forms become non-editable in this case]; then we remove the filters, existing record occurs but we cannot make any action in the card form afterwards ending with some error message from the OnInsert trigger which is called for the existing record. This behaviour occurs e.g. on Customer Card, Vendor Card, Contact. This issue occurs also in NAV4SP3 UK.

2. How to simulate:
a. Open the Customer Card
b. Filter on the No. for non-existing No. (uneditable "untitled" card occurs)
c. Remove All Filters (the card shows some existing record now)
d. Close the form (ESC), or go to the list (F5), or run any function -> the error message Customer IC1020 already has a Contact Business Relation with Contact CT000064 occurs.

Does anybody here know whether there is a fix to this issue or how to bypass it? Thanks!

Igor Chladil

Comments

  • kinekine Member Posts: 12,562
    The problem is in this code on the form, which there wasn't in previous versions:
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    RecordFound := FIND(Which);
    CurrForm.EDITABLE := RecordFound OR (GETFILTER("No.") = '');
    EXIT(RecordFound);

    The meaning of this code is to disable editation on the form if the form is filtered to nonexistent record...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • igor.chladiligor.chladil Member Posts: 28
    Thanks for your reply!

    I understand that removing that code would bypass the issue, but it would also change the behaviour. I believe that this code was introduced in order not to "auto-insert" by mistake non-existent customers when filtering for these. Is there a way to retain this feature w/o the error described before?

    I also still wonder what is causing the final error in Navision, i.e. why does Navision call the OnInsert trigger on any action when it is standing on the existing record once the filter has been removed?

    Thanks ahead for your replies,
    Igor
  • kinekine Member Posts: 12,562
    I think that the effect is connection of more things together. Because The form will lost position in the table, after the filters are removed, it will find some record and read the data, but the mode of the form will be still "INSERT" and is not updated, because the mode of the form is actualized only in some events and not during change of filters. May be when you add CurrForm.UPDATE(False) to correct point, it will solve that, but it is just a tip. It will set the mode of the form to correct one, but question is, where is the "correct point"... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • igor.chladiligor.chladil Member Posts: 28
    Thanks,

    I have not succeeded with placing the CurrForm.UPDATE as it may not be placed to the places called when the record is found. Therefore I will use completely different solution showing the info message and reseting the filter instead of making the form inedatable like ...

    Form - OnFindRecord(Which : Text[1024]) : Boolean
    RecordFound := FIND(Which);
    IF NOT RecordFound AND (GETFILTER("No.") <> '') THEN BEGIN
      MESSAGE('The customer %1 doesn''t exist',GETFILTER("No."));
      SETRANGE("No.");
      RecordFound := FIND(Which);
    END;
    EXIT(RecordFound);
    

    Regards,
    Igor Chladil
Sign In or Register to comment.