I am trying to modify a lookup to automatically filter the records on the lookup form. A fair example of what I'm trying, would be to take the typical sales order form (subform for the sale lines technically) and change the lookup on the "No." field. Upon lookup the user would still go to the "Item List" form, but all "blocked" items would be filtered out.
I have tried without success to simply use the "onlookup" function for the text box in the form code to override the default lookup functionality.
No. - OnLookup(VAR Text : Text[1024];) : Boolean
"RecordSource".SETCURRENTKEY("key");
"RecordSource".SETFILTER(Field, "filter");
IF FORM.RUNMODAL(0, "RecordSource") = ACTION::LookupOK THEN BEGIN
"No." := "RecordSource."No.";
EXIT(TRUE);
END ELSE
EXIT(FALSE);
The first problem with this is that unless I comment out the "EXIT" statements, the value selected in the modal form does not populate to the original form field. However, without the "EXIT" commands, the system thinks the "onlookup" failed, and does not "validate" the field, even though the value gets populated to the the original form field.
The second problem is that with a form such as a sales or purchase order the lookup form is based on the line's "type" value, be it G/L, Item, charge(Item), etc. So to go this route I would have to create a case statement and handle each possible "type".
What would be best is if there is a way from the modal form to add some code when it is run to determine if it is modal (there is a property that does tell this), and determine from what form the current form was called. I wouldn't want to filter say the "Item List" everytime, just when it was opened modal from the "sales subform".
Anything to point me in the right direction would be helpful.
Comments
You have to write a case statement to loockup GL, Resources, etc.
Regars
Richard
I think my hangup was avoiding the VALIDATE function which another post had mentioned shouldn't be used in a lookUP function, but it seems to be doing OK to me.
With the funtion:
"No. - OnLookup(VAR Text : Text[1024];) : Boolean"
I thought I had to return a value and EXIT was the only thing I had found so far, but this seems to not be the case either.
Thanks again for your help.
When using the VALIDATE function you should always consider what code is behind the field you are populating and whether or not you want to run this code.
i.e. if you are returning the "Description" on the sales line table, then you would want to use the VALIDATE command.
If alll you want to do is to fill the field and NOT run the code behind the field then you can use the same lines of code as described by Richard, but replace the with
Hope that helps
Dean
I think there is a problem in your sample. The line should read instead Wouldn't that help?
And therin squats the toad. A combination of my original, plus Richards, plus this little tidbit has done it. The behavior is now exactly like the default lookup as far as I can tell. This is what I've done to the Purchase order lines form OnLookup event for the "No." field. A CASE statement will be needed as well to handle "G/L Account", "Fixed Asset", and the other Types.
Thanks everyone for you input.