Problem in Lookup

mrigyamrigya Member Posts: 124
Hi all
Please tell me how can put a look on the field which is not the primary key.

Thanks
Mrigya

Comments

  • garakgarak Member Posts: 3,263
    ??? Sometimes more background infos are good ....
    do you use the TableRelation property in a table and there comes the error or what?
    Do you make it right, it works too!
  • philippegirodphilippegirod Member Posts: 191
    For instance by using LookUpOK.
    In OnLookUp trigger of the field, you can try this kind of code :
    SourceTable.RESET;
    SourceTable.SETFILTER(Field1,'%1',Filter1);
    IF FORM.RUNMODAL(Form ID,,SourceTable) = ACTION::LookupOK THEN
       "My Field" := SourceTable."Source Field";
    
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • mrigyamrigya Member Posts: 124
    when i have used the tablerelation properties then system generate the error Msg.
    Error Msg is:-
    The field below must be included in the table's primary key.

    field:- External document no.
    table: Cust. Ledger Entry
  • garakgarak Member Posts: 3,263
    So, the table relation prop. is for PK fields.
    so if you need the table relation and an lookup to an other field in the relat. Table, use the OnLookup Trigger of the field.
    Do you make it right, it works too!
  • mrigyamrigya Member Posts: 124
    I m using the table relation properties but system generate the error.
  • philippegirodphilippegirod Member Posts: 191
    And LookUpOK ?? Does it work ?
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • mrigyamrigya Member Posts: 124
    No,Actually the source table field is not a primary value.so system generate the error.
  • philippegirodphilippegirod Member Posts: 191
    But the LookUpOK function works even if the field is not included in the primary key.
    Try this :

    Create a form based on Integer, Create a var TestVarDec (Decimal).

    Add a control on your form which Source is this TestVarDec.
    On your control, on trigger "OnLookup(VAR Text : Text[1024]) : Boolean"
    Write the next code (GLEntry is a record var based on table 17.
    GLEntry.RESET;
    IF FORM.RUNMODAL(20,GLEntry) = ACTION::LookupOK THEN
       TestVarDec := GLENtry.Amount;
    

    I just tried, it works fine
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Hi Mrigya,
    take a textbox with Source Expression CustName

    <YourControl> - OnLookup(VAR Text : Text[1024];) : Boolean

    global variables
    CustName --- Code --- 50
    CustRec --- Record --- Customer
    CustFrm --- Form --- Customer List
       CustRec.RESET;
    // CustRec.SETRANGE("Your Field",FromValue,ToValue); // to set filter on lookup form
       IF CustRec.FINDSET THEN
       BEGIN
          CustFrm.SETTABLEVIEW(CustRec);
          CustFrm.LOOKUPMODE(TRUE);
          IF CustFrm.RUNMODAL = ACTION::LookupOK THEN
          BEGIN
             CustFrm.GETRECORD(CustRec);
             CustName := CustRec.Name;
          END;
       END;
       CLEAR(CustFrm);
    


    I hope, you got the Idea...!! O:)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
Sign In or Register to comment.