Returning Lookup field to calling form

I have searched the site for info on this and have come close, but no luck. Here’s my problem. In form 1, I am creating a summarized Temporary Item Ledger Table so that I get 1 record for every Item/Location Code/Lot Number. Then I call the Lookup Form (form 2) using the following code in the OnLookup trigger: IF FORM.RUNMODAL(50020,TempItemLedgerEntry) = ACTION::OK THEN BEGIN Location := TempItemLedgerEntry.“Location Code”; END; With this in place like this, my Lookup form (form 2) works fine and shows only my temporary records, but I don’t get the selected location back into form 1. If I change my code in the OnLookup trigger in form 1 to this: CLEAR(frmLocAvail); frmLocAvail.LOOKUPMODE(TRUE); frmLocAvail.SETTABLEVIEW(TempItemLedgerEntry); frmLocAvail.SETRECORD(TempItemLedgerEntry); IF frmLocAvail.RUNMODAL = ACTION::OK THEN BEGIN Location := frmLocAvail.GetRecord; END; and then inside form 2, I have the function GetRecord, which is simply: Loc := SavedRec.“Location Code”; and in the OnCloseForm trigger, I have placed: SavedRec := Rec; then I get back the proper location, but the records displayed in the lookup form (form 2) are not from my temporary summarized records, but rather from the actual Item Ledger Entry table, which now shows multiple records for each Item/Location Code/Lot Number. How can I show my summarized records and then return back the Location from the one temporary record that has been selected? Sign me, Confused [?] Thanks in advance

The first thing that comes to my mind when reading your code is that you need to check against Action::LookupOK, not Action::OK. Maybe this is all it takes to make your code work [;)]

On from lookup trigger: … if form.runmodal(form::“xxxx”, TempItemLedgerEntry) <> action::lookupok then exit(false) Text := TempItemLedgerEntry.“location code”; exit(true); Best regards from bcn.

LookupOk does need to be used when returning a record, but in this case this is not the issue. LookupOK is only going to work with records that are in the database. If you are using a temporary table, you will have to pass the record to the form, and then return the required record. i.e. Create two functions in Form 2 SetTempTable(var::TmpRecord); // must be var. create repeat until loop, and transfer the tem recors into anew tem record int he form. run the form, and in the OK button, add code to set the desired record. After closing form 2, call a function in form 2 to tell you which record was selected. This should get you started, if you need more help, just holler. (Sorry, just spent a week down South). PS if you get stuck, I can probably find an old form that deos it, I know I have done it many times.

David, I remember that I used the LookupOk way with a temptable. In my case it worked. I should look something like this : FillTempItemLedgerEntry; IF FORM.RUNMODAL(50020,TempItemLedgerEntry) = ACTION::LookupOK THEN BEGIN Location := TempItemLedgerEntry.“Location Code”; END; Francis

It depends on the code in the form. You would have to have code there that uploads the Temp variable, and then uses it. Are you sure this works if thr actual item ledre entry does not exist. By this I mean that what you are suggesting will defintely work as a replacment for the MARK function in NAvision, but I can’t see that it will work as a general solution for temporary records that you create on the fly. Still I am interested in the code on the form. I was never able to get this to work without a repeat loop populating the TempRecord ont he form, and I am very interested to see how you did this.

You can run forms with temporary tables if you write form.runmodal(…)

That’s quite usefull to know. Thanks.

Okay guys, I’ve beat my brains out on this one and think I need an additional push in the right direction. In form 1, I have now created a REPEAT…UNTIL loop that calls a function in form 2 that simply populates a temporary table there with all of the summarized records I created in form 1. (After calling a function in form 2 that deletes all of the records in that table!) Then I do the following from form 1 from the OnLookup Trigger: IF FORM.RUNMODAL(50020,TempItemLedgerEntry) = ACTION::OK THEN BEGIN Location := TempItemLedgerEntry.“Location Code”; END; That doesn’t work. So I have tried creating the following code in the OnAfterGerCurrRecord trigger: SavedRec.DELETEALL; SavedRec := Rec; SavedRec.INSERT; in order to have this SavedRec temp table contain only the one record that was selected, and then in the OnPush trigger of the OK button I added this: Location := TempLedgerEntry.“Location Code”; to save into the variable Location what the Location of the selected record was. Yes, I seem to be duplicating my effort here… Then, in form 2, I have a function GetRecord that returns the variable Loc and has the following line of code in it: Location := TempLedgerEntry.“Location Code”; Then, in form 1, I tried doing this: IF FORM.RUNMODAL(50020,TempItemLedgerEntry) = ACTION::OK THEN BEGIN Location := frmLocAvail.GetRecord; END; and that didn’t work either. I know I’m missing something real simple, but for the life of me, I can’t figure out what it is. I’m thinking that since I am doing a FORM.RUNMODAL, and then trying to query the function from a locally defined form, the 2 don’t know anything about each other. Regards, - Jim Brewer -

You’ve got two basic directions to go here. I was assuming a more comlex requirement, which requires the definition of the specific FORM as a variable, populating it, running it, then calling values from it after returning to the main form. After reviewing everything here, you probably just need a much simpler solution as suggested by Augustin and Francim. VAR Name : DataType : Subtype Loc : Record : Location Temporary = Yes OnPush() Loc.DELETEALL; Loc.Code := 'A001'; Loc.INSERT; Loc.Code := 'A010'; Loc.INSERT; Loc.Code := 'A020'; Loc.INSERT; IF FORM.RUNMODAL(0,Loc) = ACTION::LookupOK THEN ERROR(Loc.Code); seems to work fine for me

I have also used RunModal with temptables. VAR TempLoc Rec Location Temporay Form50020 form 50020 CLEAR(Form50020); Setfilters on TempLoc … Form50020.Lookupmode := TRUE; Form50020.SETTABLEVIEW(TempLoc); FORM50020.SETRECORD(TempLoc); IF Form50020.RUNMODAL = ACtion::Lookup THEN BEGIN Form50020.GETRECORD(TempLoc); NewLocation := TempLoc.CODE; END; Steve

I don’t want to be a pain, but it’s probably too late for that. The issue isn’t temp tables, it’s calculated records in a temp table. I am combining multiple records from the Item Ledger table into a single record in a temp table. I’m having to filter on the Item Ledger table for the subset I want, and then as I read through them, I see if I have already written a record to the temp table with those same filters. If not, I add 1 to a Sequence and INSERT the record - if it’s already there, I add to the quantity in the existing record and MODIFY the existing record. Therefore, by the time I get done reading through the real table, I have records in my temp table that have nothing to do with reality. What we have discovered is that if you use the syntax FORM.RUNMODAL(50020,TempItemLedgerEntry) which is my calculated temp table, there is no way to return any fields from the selected record (which really isn’t a real record) in form 50020. If you use the syntax Form50020.RUNMODAL, it simply uses the filters that you have set with SETTABLEVIEW, etc. on the real table. I think I’ll call it a day and tell the client that they will just have to copy from the lookup form and paste back into the detail line that called the lookup form. I don’t see how I can justify billing them for any more work on this one. Thanks to all who participated.