Code - OnLookup(VAR Text : Text) : Boolean IF Type = Type::BU THEN BEGIN CLEAR(R_DimensionValue); R_TempDimensionValue.DELETEALL; R_DimensionValue.SETRANGE("Dimension Code",'BU'); R_DimensionValue.SETRANGE(Blocked,FALSE); IF R_DimensionValue.FINDSET THEN REPEAT IF NOT GET(Type::BU,R_DimensionValue.Code) THEN BEGIN R_TempDimensionValue := R_DimensionValue; R_TempDimensionValue.INSERT; END; UNTIL R_DimensionValue.NEXT = 0; IF PAGE.RUNMODAL(0,R_TempDimensionValue) = ACTION::LookupOK THEN Code := R_TempDimensionValue.Code; END;
Answers
you should assign R_TempDimensionValue.Code to Text (the trigger's VAR parameter), not to Code.
And the flaw that broke your code: you need to return TRUE on successful lookup.
And finally, please, when posting code in this forum, use [code]...[/code] tags, so indentation is preserved and your code is much more easily readable. (See the Paragraph symbol above the edit box.)
Thx for your answer. I tried to assign the Text variable, but no change.
I finally fixed the problem by creating a record variable instead using the default rec record. I replaced the
and everything is OK now.
The code change, of which you claim fixed your issue has nothing at all to do with returning the value chosen in the lookup, but only with the records shown in that lookup page.
You claimed, however:
Even if this solved your issue, you still should implement the changes I gave you. But they must go together. The value of Text is only filled into the control if also you return TRUE.
The difference is not widely understood, apparently not even by Microsoft, looking at most of their standard code:
If the lookup is not coded, but solely results from the TableRelation trigger, and when you use the coded approach assigning to Text and returning TRUE, the value you select is not yet validated but simply filled into the control. The user has now a chance to press Esc and the original value reappears, just as if he did not lookup the value at all, but typed it. If he leaves the field any other way, normal validation occurs, just as if typed in.
If you assign the value directly to SourceExpression, and do not return TRUE, the system is in an entirely different state. Pressing Esc now will (try to) close the page, writing the change to the database. Moreover, the no control or field validation is called. You do not have any chance of calling the OnValidate trigger of the page in this situation, but may explicitly call the fields OnValidate by using VALIDATE(SourceExpression) in your Lookup code. Take care, though: Microsoft says (in Best Practices) about field OnLookup, that, if the validation may cause an error, you should do the validation on a copy of Rec. I don't know if this does apply to control OnLookup triggers as well.
Unfortunately, with field OnLookup triggers, you do not have any chance of doing the same as a TableRelation lookup does. The parameters needed for this are simply missing.