Hi, In Navision 3.01B; - lookup a value from any main form in a specific lookup form - without using code - click OK on the lookup form you still can cancel the choosen value already returned to the main form after lookup by pressing ESC. Some use lookup to see what’s behind a value in a main form, if the main form is not informative enough [:)]. Clicking Cancel would be the right answer for leaving the lookup form without change, but with OK there’s also nothing permanently changed Using Code instead on the Main form’s field onlookup trigger to do the same, ESC doesn’t work anymore to cancel the choosen value already returned to the main form. Is it possible to keep the same behaviour as without using code? My code CLEAR(CustomerListForm); CustomerListForm.SetFilters(“Customer Type”::“Inv. Addr Consumer”); IF (“Bill-to Customer No.” <> ‘’) THEN CustomerRec.GET(“Bill-to Customer No.”); CustomerListForm.SETRECORD(CustomerRec); IF CustomerListForm.RUNMODAL = ACTION::LookupOK THEN BEGIN CustomerListForm.GETRECORD(CustomerRec); “Bill-to Customer No.”:=CustomerRec.“No.”; END;
on form basis, you have the OnLookup Trigger. it passes you the parameter Text where you can store the value you have looked up. and then set the result of the trigger to true or false, either if the user has accepted or aborted the loojup. now if you do it this way, navision should treat your lookup as if you changed the control (not the field in the control), and should allow ESC to cancel your entry. if you do it like you did, i guess navision will write the value you looked up directly into the field and then update the control where it is shown. therefore ESC does not work, because according to navision, you didn’t even edit the control.
Thanks for your reply, but I’m failing to understand how to pass the return value to the form only.
In Form designer, you need to select the text field for which you want to implement the lookup, then go to C/AL code. You will see an OnLookup trigger, which is declared with a parameter of type Text and a Boolean return value. You have to put your lookup code into this trigger and then return TRUE or FALSE, depending on whether the user chose OK or Cancel.
Sorry Heinz, I Already implemented the coding (see my first posting) as you described. It’s not the issue of the user choosing OK or Cancel and then handling it. I’m trying to mimic Navisions standard behaviour; Regardless of user choice OK or Cancel showing the lookup value, but actually not writing it untill the moment the field loses focus or go back to the old value if the user presses ESC, after the value is lookuped.
Well no Peter - there’s a subtle difference, which has already been described by our freaky bassist [;)]: Instead of the direct assignment of the chosen value in your code (“Bill-to Customer No.”:=CustomerRec.“No.” you need to put the value (CustomerRec.“No.” in your case) into the Text parameter (which is a VAR parameter, so the value will be returned to the form) and set a return value for the trigger. According to Freak, this will result in the trigger behaving like the standard lookup functionality (I tried it with one of my Report’s request form’s lookup triggers, and it works). So, your code (in the text field’s OnLookup trigger) should look like:
IF CustomerListForm.RUNMODAL = ACTION::LookupOK THEN BEGIN //CustomerListForm.GETRECORD(CustomerRec); // I think this is not necessary Text:=CustomerRec."No."; EXIT(TRUE); END ELSE EXIT(FALSE);
Thanks Freaky Bassplayer and Heinz, The last posting made clear what I failed to grasp. I’ve seen a lot of examples on this forum concerning lookup in coding, but I missed to see the Text VAR parameter. It works nice. P.S. you do need the GETRECORD.
Originally posted by pb
It works nice.
P.S. you do need the GETRECORD.
Oh yes, right, that’s because you use the formvariable.RUNMODAL version. I always use the FORM.RUNMODAL(FormNumber, RecordVar) variant, which allows me to retrieve the selected record directly from the variable passed to RUNMODAL. The first version does not accept any parameters. I did not realize this difference when I wrote my previous post.