Automated lookup doesn't point to right record

To the question Why Navision doesn’t run Onvalidate with a Onlookup trigger ? I think there’s two problem with Onvalidate implementation. 1) When Navision run a custom lookup trigger, Navision is not able to determined if the user choose Cancel or Ok. Therefore, how to emulate standard behavior “execution of onvalidate trigger if OK”. 2) OnValidate is executed if the input is edited, and not only if the value changes. If you add a space at the end of a value and clear it, the value doesn’t change, but the trigger is run. With a OnLookup trigger, How could Navision handle this ? - store oldvalue - run trigger OnLookup (value may be changed) - user exits control - compare currentvalue with oldvalue - if different run trigger OnValidate it’s not really the same [^] Moreover, there’s a side effect, when you change the value in the lookup trigger and you press escape, For Navision the field is not considered as edited and the old value isn’t restored.[Oops!] It’s difficult to be perfect … [;)]

Next set !! If you see the Onlookup trigger on a form. It’s different. You have Onlookup(var text: text[1024]):boolean Just EXIT(TRUE) tells Navision the Lookup return OK And Therefore, OnValidate trigger is executed [8D] Ok, you have to set text variable and not directly assign field. Thus, tell me why Why Navision doesn’t do the same with OnLookup Table Trigger Just a little boolean return value and you close the problem [V] It’s allways possible to be more and more perfect [;)]

So I finally installed an old version and tried it out. I must be getting old because it doesn’t happen as I was positive it did… There is a difference but not quite as I remembered and wrote about. The test was to create a new empty database with a new company (no objects in it, except for the system tables). I then created 2 tables: “Table 1” with 3 fields: “Code”, “Code 2” and “Code 3” “Table 2” with 1 field: “Code 2” “Table 1”.“Code 2” has a table relation to “Table 2”.“Code 2”. There are also 2 Forms - “Form 1” and “Form 2” - one for each table. In Table 2, I inserted 3 records with values “1”, “2” and “3”. The OnValidate trigger of “Table 1”.“Code 2” has the following code: “Code 3” :=“Code 2”; So that whenever Code 2 (the field which is related to Table 2) is validated, we know it happened by seeing Code 3 also change. Are you following me?.. [B)] We now have a scenario where the Lookup is provided by Navision automatically. I will use the lookup and note the behaviour. – Experiment 1 – The result in 2.50 is: - Table Level: Press the lookup button, select the value, press OK, value is copied to “Table 1”.“Code 2”, after exiting the field, “Code 2” is validated and “Code 3” is updated to show the same value. - Form Level: Same behaviour as Table Level. The result in 4.0 SP1 is: - Table Level: Same behaviour as 2.50. - Form Level: Same behaviour as 2.50. OK, the default, automatic, system-provided Lookups haven’t changed. The next step is to design Table 1, create a record variable pointing to Table 2 and write the following code in the OnLookup trigger of field Code 2: IF FORM.RUNMODAL(0,Table2) = ACTION::LookupOK THEN “Code 2” := Table2.“Code 2”; Notice that I am not validating the field, I am just making an assigment. – Experiment 2 – 2.50: - Table Level: The Code 2 field is not validated, Code 3 remains at all times intact. - Form Level: Same behaviour as above. 4.0 SP1: - Table Level: Code 2 is not validated, the funny thing is that the lookup form never returns the result. The contents of Code 2 remain the same no matter what record was selected when pressing OK - that’s odd… - Form Level: Same behaviour as 2.50, just above. Finally, bear with me…, I change the lookup code to IF FORM.RUNMODAL(0,Table2) = ACTION::LookupOK THEN VALIDATE(“Code 2”,Table2.“Code 2”); – Experiment 3 – 2.50: - Table Level: Code 2 is validated as soon as I press the OK button on the Lookup form. Code 3 is updated before I even exit Code 2. - Form Level: Same behaviour as above. 4.0 SP1: - Table Level: Here we have the same behaviour as on the previous experiment. The lookup form never returns the selected record… - Form Level: Same behaviour as 2.50, just above. So, maybe the change I remember was only the Table Level lookups being “disabled”. Still, I can not understand why the lookup form only returns the selected value when used from a form and not from a table… Well, that’s enough for me today. I must be quite mad to almost turn this into an essay. Any comments are welcome.

Hi Nelson, thanks for the tests. We just checked the same thing in a 4.00 SP1 DE and it still will not populate the lookup value into the field. Has anyone an idea when that behaviour changed?