Using OnLookup Trigger

Hello, I’ve searched through the archives but can’t seem to find my answer… I am having to use the OnLookup trigger in the “No.” field of the “Sales Line” table (table 37) because I need to filter some items in the Item List. I am using the code below to do this… >>>No. - OnLookup()<<< CASE Type OF Type::" ": BEGIN fStdTextList.LOOKUPMODE(TRUE); IF fStdTextList.RUNMODAL=ACTION::LookupOK THEN BEGIN fStdTextList.GETRECORD(mStdText); VALIDATE(“No.”,mStdText.Code); END; END; Type::Item: BEGIN mSalesHeader.GET(“Document Type”, “Document No.”); fItemList.fLimitAllowedItems(mSalesHeader); fItemList.LOOKUPMODE(TRUE); IF fItemList.RUNMODAL=ACTION::LookupOK THEN BEGIN fItemList.GETRECORD(mItem); VALIDATE(“No.”,mItem.“No.”); END; END; … … … It works OK for the most part except for a couple of things. I really don’t want to run the OnValidate code until I leave the field, but apparently this is not possible. The OnValidate code runs (because of the “Validate” statement) as soon as you push the OK button. But…The OnValidate does not fully run. If I have extended text, the extended text does not get pasted into the sales lines. If I manually enter the item number, the extended text pastes properly. What is causing this? I read on other posts on this topic that, if you want to run the OnValidate code, you must put “Exit(True)” between the Begin & End after the Action::LookUpOK. But when I put in the “Exit(True)” line I get an error. I am thinking that Exit(True) should only be used if the lookup code is put on a form rather than in the table. I am trying to keep all the code within the table if possible. Any help would certainly be appreciated. Best regards, Mark.

Hi Mark, If you look at any of the Subforms for Sales Lines, you will see that the function to insert Extended Text is run from the OnAfterValidate trigger of the “No.” textbox. This must be causing the strange behaviour with Extended Texts. Maybe you will also need to put your code at Form level (which is not your desired solution). There will be someone with a better answer for you, I think. I have only one question: Can you not change the TableRelation property for the “No.” field? If it is possible to define a TableRelation filter like the one on your fLimitAllowedItems function, you wouldn’t even have to worry about any of these problems.

Nelson, Thanks for your reply. I am afraid that you are correct - I will probably have to put code on the form. I cannot get away with changing the table relation to the item table as the items that I need to filter are based on values in another table. There are multiple conditions that need checked in this other table which then marks the item records. Thanks again, Mark.

Hello Mark: Do not know if this would work by simply glancing through what you are trying to do, but what if you put a function that waits for an ok condition if successful. This function would call the extended text routine and should return ok if the validate was succesful. Just a thought. fItemList.GETRECORD(mItem); IF ValidateRecord THEN END; ELSE Error(’’); //some catcher Debug only? ValidateRecord { VALIDATE(“No.”,mItem.“No.”); //below copied from the form lvl. u could simply call the form but passing parms between objects //gets a little messy. U could take it and pass it back //to the form or whatever text object you want with a few mods and error checks. Even from the //table lvl. IF TransferExtendedText.SalesCheckIfAnyExtText(Rec,Unconditionally) THEN BEGIN CurrForm.SAVERECORD; TransferExtendedText.InsertSalesExtText(Rec); END; IF TransferExtendedText.MakeUpdate THEN UpdateForm(TRUE); } Just a thought. best rgds. Owen

In form trigger OnLookup NO, write: CASE Type OF Type::" ": BEGIN fStdTextList.LOOKUPMODE(TRUE); IF fStdTextList.RUNMODAL<> ACTION::LookupOK THEN exit(false); fStdTextList.GETRECORD(mStdText); text := mStdText.Code; END; Type::Item: BEGIN mSalesHeader.GET(“Document Type”, “Document No.”); fItemList.fLimitAllowedItems(mSalesHeader); fItemList.LOOKUPMODE(TRUE); IF fItemList.RUNMODAL<>ACTION::LookupOK THEN EXIT(FALSE); fItemList.GETRECORD(mItem); TEXT := mItem.“No.”; END; END; EXIT(TRUE); Best regards from BCN.