Lookup without Primary Key

MokafMokaf Member Posts: 13
Hi.

I want to lookup a field from a table, but this field doesn't belong
to the primary key of that table. I don't know if there is a way of
doing this.

Help please.

Comments

  • sggsgg Member Posts: 109
    Try something like this:

    IF Form.RUNMODAL(form::FormName, LkTable) = ACTION::LookupOK THEN
    LkValue := LkTable.LkField;


    The Form::FormName should be a Listing or Lookup Form for the Table where you want to pick the Field from.

    Put the codes in the OnLookUp Trigger of the TextBox for the Field you have in mind LkValue
    Sunday, Godwin G
  • EstefaniaEstefania Member Posts: 16
    Yo have to program it on the OnLookup trigger, for example to get the address from the Customer table you would have to do something like this:


    Customer -> Record var. table Customer
    CustomerList -> Form var. form Customer List


    CustomerList.LOOKUPMODE(TRUE)
    IF CustomerList.RUNMODAL = ACTION::LOOKUPOK THEN
    CustomerList.GETRECORD(Customer)



    After running this you will have the record selected on the Customer list, and you can get the field you want, for example the address, that is not the primary key. You can filter the records you see on the list using the property SETTABLEVIEW of the form.
  • MokafMokaf Member Posts: 13
    Thank you so much Sgg and Estefania.

    Both of the solutions solve my problem.

    Anytime you need help I'll be 100% available.
  • jhoekjhoek Member Posts: 216
    At the risk of sounding religiously strict about these matters: I think in 9 out of 10 cases where you need the sort of functionality you requested, there's a major flaw in the data model. Just a warning... :wink:
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • MokafMokaf Member Posts: 13
    Jan, I think you are completely right and I'm glad you said
    9 of 10, there's a 10% chance for my data model to be correct :)

    I found another situation where I needed to use Sgg's and Estefania's
    solution:
    - I wan't to lookup a table in a report's request form, but the field
    doesn't belong to any of the DataItems in the report.

    Could you tell me something about this issue?
    Thanks.
  • jhoekjhoek Member Posts: 216
    Sure! Assuming the primary key that you need to lookup consists of only one field, here's what I would do:

    - Create a variable of the same type as the primary key field, and make it the SourceExpr of the textbox you place on the request form;
    - Set the textbox' TableRelation to the related table;
    - Set the textbox' CaptionML to the appropriate value;

    Primary key values consisting of more than one field require some additional programming in the textbox' OnLookup and OnValidate trigger.
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • LambaLamba Member Posts: 260
    Hi,
    When we make a PO, on selecting Item as the Type on lookup of Item list in No. field, only those items must be visible those are having a boolean true. How this can be done.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    This is a post from 2005. 8 years ago.

    Please start a new thread and also explain what you have tried so far.
Sign In or Register to comment.