Table Relation to the Item Table

tompynationtompynation Member Posts: 398
Hi,

I created a form. Added a textbox to it and created a global variable of type Code.
I added this Global Variable as source expression for my Textbox.

In the Properties of the textbox i add following table relation:
Item."Custom No." WHERE (Product Group Code=CONST(COLORMIX))

Now when i run the form and use the lookup of the textfield to select a "Custom No." i receive the error that:
The field below most be included in the table's primary key.
Field: "Custom No."
Table: Item

Why is this? Can't we create a table relation to a field that is not inside the primare key?

Answers

  • tompynationtompynation Member Posts: 398
    Solved by adding following code to the OnLookupTrigger of the textbox:

    lv_Item.RESET;
    lv_Item.SETRANGE("Product Group Code",'COLORMIX');
    IF FORM.RUNMODAL(31,lv_Item) = ACTION::LookupOK THEN
    gv_ProductGroup := lv_Item."Sidec No.";

    But still, is this some kind of bug in NAV that you cant set the same relation through the TableRelation property?
  • awarnawarn Member Posts: 261
    But still, is this some kind of bug in NAV that you cant set the same relation through the TableRelation property?

    This is not a bug - it is just the way it works. There can be MANY items whose "Custom No." field matches your criteria, not just one. But you are telling the system that the user will select ONE record, but you are not giving the system any way to identify which record needs to be selected (the only way to do this is to reference the primary key, which is what Navision is asking for).

    The solution you have is the proper way to fill the field on your form.

    -a
Sign In or Register to comment.