Create Lookup Functionality with code

StephenGStephenG Member Posts: 99
edited 2003-10-14 in Navision Financials
Hi,

I'm trying to create the standard lookup functionality with code :?


ShipToCodeFilter Text variable on the RequestOptionsForm.

ClearOnLookup = NO
ValidateTableRelation = No
TextBox  ShipToCodeFilter.
OnLookup(VAR Text : Text[250];) : Boolean
IF CustNoFilter = '' THEN
  ERROR('You must select a customer No. if you want to filter on Ship-to Code');

ShiptoAddress.SETFILTER("Customer No.",CustNoFilter);
IF FORM.RUNMODAL(0,ShiptoAddress,ShiptoAddress.Code) = ACTION::LookupOK THEN BEGIN
  IF ShipToCodeFilter <> '' THEN
    ShipToCodeFilter :=  ShipToCodeFilter + ShiptoAddress.Code
  ELSE
    ShipToCodeFilter := ShiptoAddress.Code;
  ShipToCodeFilter := UPPERCASE(ShipToCodeFilter);
END;

What I'm trying to do is that depending on whether the text in the textbox (where I start my lookup from) is selected, the action either overwrites the existing text (if the text was selected), or appends the newly looked up value behind the cursor.

So, if I have "Addr1.." in a textbox and do a lookup to Addr2, then my textbox should read "Addr1..Addr2" ONLY if "Value1.." was not selected (highlighted). If "Addr1.." WAS selected, my textbox should overwrite "Addr1.." with "Addr2", rather than append to it.


This is in a Financials 2.01 database.
Answer the question and wait for the answer.

Comments

  • jyotsnasjyotsnas Member Posts: 62
    Hi Stephan

    If I got it right, I have solution to your problem.
    I will setup the situation as ---
    TextBox -- On which lookup is needed
    LookupForm - Form on which lookup is made
    LookupSource - source table of lookup form
    GetValue -- A getter function in LookupForm that returns selected value (Address in ur case)
    TextBox : OnLookup
    
    LookupSource.reset;
    LookupSource.setfilter( ........... );
    LookupForm.settableview ( LookupSource );
    LookupForm.lookupmode := true;
    
    if LookupForm.runmodal = action::lookupOK then
      TextBox := TextBox + LookupForm.GetValue;
    
    clear( LookupForm )
    

    I Hope this helps.

    Regards,

    Jyotsna Sonawane
    Navision Developer
    ______Doubt is the father of Invension_______
  • eromeineromein Member Posts: 589
    Guys,

    You are forgetting to return a value!

    Following trigger can be found on a form.
    Field - OnLookup(VAR Text : Text[1024];) : Boolean
    

    It's very important you don't fill any fields from this trigger. the only thing you can fill is the Text variable. Don't go validating triggers from this trigger. Plus the function needs to have a boolean returned to know if you found a value or pressed the cancel button.
    Field - OnLookup(VAR Text : Text[1024];) : Boolean
    
    rec.setcurrenkey&#40;foo,bar&#41;;
    rec.setrange&#40;foo,bar&#41;;
    rec.setrange&#40;bar,foo&#41;;
    
    if form.runmodal&#40;0,rec&#41; = action::lookupok then begin
      text := rec.foo;
      exit := true;
    end else
      exit := false;
    

    Code have not been tested!

    OOooh and do go generating errors from this trigger. This trigger should always start and finisch, return 2 variables.
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
Sign In or Register to comment.