Assign data in a LookUp

AlkroAlkro Member Posts: 115
Hi,

I've a Form that contain a textbox (the txtbox shows a field of a table), and this textbox have a call to another Form (lookup). I want that, when i select any data in the lookup, this data save in the textbox and the field in the table.

The textbox has LookUpFormID: 50001 and

SolOrigen - OnLookup(VAR Text : Text[1024];) : Boolean
FORM.RUNMODAL(50001);

But i don't know how to say "Save this, here"

I don't find the way...

Regards

Comments

  • krikikriki Member, Moderator Posts: 9,112
    -fill in the TableRelation-property of the field in the table (in you case the source table of your form 50001).
    -In the table (the sourcetable of your form 50001) where the value is that you want to select, you just have to put property "LookupFormID" to the form of the list (in your case 50001).

    An example of this system:
    -Table 3 : check the property "LookupFormID"
    -Table 36 : field "Payment Terms" : check property "TableRelation"
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    Well.

    i added a field in table "Purchase Header" called DATA.

    In a form, i have a textbox that show this data. I want that, when an user wants to change this data, push on the lookup in this textbox and select one record of this field in table Purchase Header.

    I,ve tried this you tell me, but doesn`t work.
    -fill in the TableRelation-property of the field in the table (in you case the source table of your form 50001).
    Is the same table
    -In the table (the sourcetable of your form 50001) where the value is that you want to select, you just have to put property "LookupFormID" to the form of the list (in your case 50001).
    In the Table Properties? How? Because i open the Design Mode, but only can view the fields properties.

    Maybe C/AL code?

    Can be, in OnPush() the ComandButton to Accept the lookup Form, give the data of the selection to the textbox in Form???

    Regards
  • kinekine Member Posts: 12,562
    Common structure of OnLookup trigger:
      RecVar.SETRANGE(...);  //Setting filters - what I want to see in the list
      ...
      if FORM.RUNMODAL(0,RecVar) = Action::LookupOK then begin
        //The action, which will be performed after user click OK button.
        //Selected record is returned in RecVar...
        Rec.VALIDATE(MyField,RecVar.FieldValue);
      end;
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,112
    Lets start from the beginning:
    -you have a new table and a new form (your form 50001).
    In the table you need to set tableproperty "LookupFormID" to your form. This tells the table to use the form when an lookup-action is done on the form. Your form needs 2 buttons : Ok and Cancel with certain properties set (if you create a new form connected to a table with the form-wizard, this is done automatically).
    To view the table-properties of a table, go into design and go to the place to create a new field in the table without creating the field. Then you will see the tableproperties.

    -in field of the other table ("Purchase Header".DATA), you just need to set the property TableRelation of the field.

    Don't run table "Purchase Header" directly because it is possible the lookup to select a value doesn't work. But put the field on a form and run that form.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    Lets start from the beginning :).

    I use Form 50 (Purchase Order). I'm created a Textbox where i can saw number of application for a order.
    Ex. Order: 11001 ---> Application: 0012

    Well for this data (Application) i create in Table 38 a new field, called "OLD APP".

    There is cases that one Application maybe create various Orders. Application: 0013 ---> Order:11002, Order:11003. I want the user click on this textbox of Form 50 (ORDER), and select Application number from a new Form where can see all the orders with their applications. When select, aplly this value in Table 38 new field.

    Actually i can saw the new form, cliking textbox, but when i select the application, the textbox don't take this value.
  • krikikriki Member, Moderator Posts: 9,112
    Alkro wrote:
    Lets start from the beginning :).

    I use Form 50 (Purchase Order). I'm created a Textbox where i can saw number of application for a order.
    Ex. Order: 11001 ---> Application: 0012

    Well for this data (Application) i create in Table 38 a new field, called "OLD APP".

    There is cases that one Application maybe create various Orders. Application: 0013 ---> Order:11002, Order:11003. I want the user click on this textbox of Form 50 (ORDER), and select Application number from a new Form where can see all the orders with their applications. When select, aplly this value in Table 38 new field.

    Actually i can saw the new form, cliking textbox, but when i select the application, the textbox don't take this value.

    So, you don't have a new table with the Application-numbers in it? But you show and select a purchase order that has some application number.
    This is the code for it: (like kine already wrote).
    OnLookup-trigger of the field
    recPurchaseOrder.RESET;
    recPurchaseOrder.SETCURRENTKEY(....);
    recPurchaseOrder.SETRANGE(.....); // put the filters you need
    IF FORM.RUNMODAL(FORM::"New Form",recPurchaseOrder) = ACTION::LOOKUPOK THEN BEGIN
      VALIDATE("OLD APP",recPurchaseOrder."OLD APP");
    END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    I'm doing anything wrong :(, because no work like i want

    In Form 50 (Purchase Order) i have the Textbox with SourceExpression "Purchase Header.OLD APP". The Textbox Properties, in LookUp is YES, and C/AL Code TextBox.LookUp() i put FORM.RUNMODAL(50013);

    When i push on LookUp in Textbox, the 50013 Form appears. And now, i want select one field in this Form 50013 (OLD APP one of this) and when i push Accpt in the form, the form close and the Textbox have the "OLD APP" Value.

    Last parrafe is only i need.
  • krikikriki Member, Moderator Posts: 9,112
    Alkro wrote:
    In Form 50 (Purchase Order) i have the Textbox with SourceExpression "Purchase Header.OLD APP". The Textbox Properties, in LookUp is YES, and C/AL Code TextBox.LookUp() i put FORM.RUNMODAL(50013);
    Best put the code for the lookup of the field in the table, not in the form.

    Alkro wrote:
    When i push on LookUp in Textbox, the 50013 Form appears. And now, i want select one field in this Form 50013 (OLD APP one of this) and when i push Accpt in the form, the form close and the Textbox have the "OLD APP" Value.
    Once you put the code in the table, post the code you put so I can check it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    kriki wrote:
    Best put the code for the lookup of the field in the table, not in the form.
    OK. The form open OK :). Table 38, OldApp field, LookUp().
    kriki wrote:
    Once you put the code in the table, post the code you put so I can check it.
    I don't know the code. This is the problem. I don´t know how can i get the value from Form 50013 pushing "Accept" bottom and save it in OldApp field (Table 38) in the open Order from form 50.

    Now in the OldApp - LookUp() only have FORM.RUNMODAL(50013);

    Regards
  • krikikriki Member, Moderator Posts: 9,112
    Alkro wrote:
    I don't know the code. This is the problem. I don´t know how can i get the value from Form 50013 pushing "Accept" bottom and save it in OldApp field (Table 38) in the open Order from form 50.

    Now in the OldApp - LookUp() only have FORM.RUNMODAL(50013);
    This is the code:
    recPurchaseOrder.RESET;
    recPurchaseOrder.SETCURRENTKEY(....);
    recPurchaseOrder.SETRANGE(.....); // put the filters you need
    IF FORM.RUNMODAL(FORM::"New Form",recPurchaseOrder) = ACTION::LOOKUPOK THEN BEGIN
      VALIDATE("OLD APP",recPurchaseOrder."OLD APP");
    END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    Ohohoh,

    Yes, i put the code (modify for me)and work...






    ¡¡FINE!! :)

    Thank you kriki ;)
  • ajhvdbajhvdb Member Posts: 672
    recPurchaseOrder.RESET; 
    recPurchaseOrder.SETCURRENTKEY(....); 
    recPurchaseOrder.SETRANGE(.....); // put the filters you need 
    IF FORM.RUNMODAL(FORM::"New Form",recPurchaseOrder) = ACTION::LOOKUPOK THEN BEGIN 
      VALIDATE("OLD APP",recPurchaseOrder."OLD APP"); 
    END;
    

    This doesn't work if you RUN the table from the Object designer and push F6 and click on OK :shock:

    But run a form, push F6 and click OK it works. :?:
    I'am using 4.02
  • krikikriki Member, Moderator Posts: 9,112
    ajhvdb wrote:
    recPurchaseOrder.RESET; 
    recPurchaseOrder.SETCURRENTKEY(....); 
    recPurchaseOrder.SETRANGE(.....); // put the filters you need 
    IF FORM.RUNMODAL(FORM::"New Form",recPurchaseOrder) = ACTION::LOOKUPOK THEN BEGIN 
      VALIDATE("OLD APP",recPurchaseOrder."OLD APP"); 
    END;
    

    This doesn't work if you RUN the table from the Object designer and push F6 and click on OK :shock:

    But run a form, push F6 and click OK it works. :?:
    I'am using 4.02
    I also noticed the problem.
    In older (I think <=3.7) versions that worked. At least I can't remember having encountered the problem.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ajhvdbajhvdb Member Posts: 672
    Thx for confirming i'm not completely mad :x
    I just wanted to change the onlookup in a few minutes and after an hour of disbelieve gave it up and posted this message.
Sign In or Register to comment.