Table OnLookup

Hi there just wanted to ask whats wrong here: i wrote an onlookup in a table. it displays the form and does everyhthing right, BUT it does not save the value selected in the table. used this code here: if lookup.runmodal = lookupok then begin lookup.getrecord(somerec); rec.field1 := somerec.field2; end; after the onlookup trigger the “field1” field is blank. i also tried to validate and than modify(treu) … nothing. i even displayed the content of “field1” just before the trigger is done, and the value is correct, but after the trigger is finished, the value of “field1” seems to be lost somewhere in the dark holes of navision …

Well, i am not really sure what is wrong with your code, but I suggest that you try to debug these lines to figure out where exactly the value is not assigned correctly. I usually use the following statement and it works fine: var: ContPers Rec Contact

IF FORM.RUNMODAL(FORM::"Contact List",ContPers) = ACTION::LookupOK THEN.....

the selected record of the form is then stored in ContPers. Hope this helps. Nils

well, the lookup works fine and i get the right value too, but it seems that the value is not stored correctly after the perfomed lookup. do i need to call something to make it right or what?

I don’t really get your question… what do you want to achieve? Once the record is storde in the declared variable you can perform whatever you need… in case you want to assign some values to other variables (e.g. OtherRec), don’t forget the OtherRec.MODIFY… maybe you can just clarify your problem a bit. Saludos Nils

my problem is that: i executed the lookup and have the value which is to be stored in a field in a variable. now i’d like to write it to the field. after writing VALIDATE(field, value) i do a MESSAGE(field) and Navision pops up a message with the RIGHT content. BUT after having th OnLookup of the table finished, NOTHING is insied field again! its blank! i DO a Rec.modify;

Please post the entire code of that trigger and indicate which table and which trigger you are using… as far as your description is concerned it should work out… Saludos Nils

DocSource is determined correctly before. CASE DocSource OF 0: ERROR(‘Specify a valid document type!’); 1: IF FORM.RUNMODAL(FORM::“Sales List”, SalesHeader) = ACTION::LookupOK THEN SelectedNo := SalesHeader.“No.”; 2: IF FORM.RUNMODAL(FORM::“Purchase List”, PurchaseHeader) = ACTION::LookupOK THEN SelectedNo := PurchaseHeader.“No.”; 3: IF FORM.RUNMODAL(FORM::“Job Budget”, Job) = ACTION::LookupOK THEN SelectedNo := Job.“No.”; 4: IF FORM.RUNMODAL(FORM::“Posted Sales Invoices”, SalesInvHeader) = ACTION::LookupOK THEN SelectedNo := SalesInvHeader.“No.”; 5: IF FORM.RUNMODAL(FORM::“Posted Purchase Invoices”, PurchaseInvHeader) = ACTION::LookupOK THEN SelectedNo := PurchaseInvHeader.“No.”; END; VALIDATE(Rec.“Document No.”, SelectedNo); MODIFY(TRUE); “Closed By”:=‘figuar’; // just for testing

Depending on the field which calls this trigger I can see a problem with your code… Just for clarification: the code you posted is in the OnLookUp trigger of the field “Document No.”? If this is correct then you do not need the MODIFY statement, as this part gets executed automatically when the OnValidate of that field is finished and the problem is that you MODIFY the record, and the original record gets saved again after the OnValidate of the field terminates. Simply use the following line, instead of the VALIDATE and MODIFY lines: “Document No.” := SelectedNo; Hope this helps.

thanks, but: you’re right, it is in the onLookUp of “Document No.”. i removed any validate and modify and it still does not work

…very strange indeed, if you don’t mind, why don’t you send me that table (text format) and I have a look at it and try to figure out what is going wrong… (

Really strange but in the simple table view the mentioned field did not get updated after the value had been asigned in the OnLookup trigger - once adding the field to the normal form, the selected value got assigned correctly to the field. …there is definitly some time necessary to get used to the “new” 3.60 features [;)] Saludos Nils

Hi, Instead of writing code in On Look up of “Document No.”, write the code in On look up of variable. After u get the value in variable then u can update document no… Check this should work Bobby

ahed 4, If it makes you feel better, I’m having this same problem too. I’ve worked with Navision for some time now (4 years or so). I’ve used this code a billion times (well, maybe not quite that many times…), and it always works: IF FORM.RUNMODAL(0,Customer) = Action::LookupOK then VALIDATE(“Cust No.”,Customer.“No.”); And just yesterday it didnt work. I have tried writing it in different ways, declaring the form (customer Lookup) as a variable, assigning the value rather then validating, etc etc. I have run it through debugger, and yes, it does get the value correctly. It is almost as if the OnLookup trigger is incapable of making changes to the table, as I have tried to do other things within the OnLookup trigger (as an experiment). I’ve tried it in a number of differnet databases (all 3.01B), on a workmates PC, server and local (all C/Side). All get the same result. Nobody here can explain it. Anyway, enough of my rambling. If anyone could help it would be much appreciated.

I have found a workaround for this. I dont know if it was what Bobby Srivastava was refering to, but what he said gave me the idea. Lets pretend for this example I am wanting to return the Customer No. to a new table. I already have a “Cust No.” field on this new table. 1. On the new form, I declare a variable, CustNo. 2. On the new form, I create a new text control, and put CustNo as the source expresion. 3. In the OnLookup trigger of this new control, I put the following code: IF FORM.RUNMODAL(0,Cust) = ACTION::LookupOK THEN VALIDATE(“Cust No.”,Cust.“No.”); CurrForm.UPDATE(TRUE); 4. In the OnAfterGetRecord trigger of the form I put this code: CustNo := “Cust No.”; There. it all seems to work. Kind of a dodgey work around for what seems to be a rather big bug with Navision. I am yet to get through to my local support about this… Anyway, I’m off to make back those hours I lost yesterday on this problem…

Actually, there is no need to be playing around with variables and stuff. Just put the code in the OnLookup trigger of the form control. Thats probably what Bobby was refering to.

Shannon, it’s even simpler than that… your code in the first instance is correct, the problem is that apparently the table view doesn’t get updated correctly. If you test your solution/code opening the form of that table, you will notice that your code works fine… There is also no code necessary on the form control - it would not be too handy to update every single form where you use that lookup, instead much easier to have it on the table directly. E.g. have a look at table 81, Field 36 Applies-to Doc. No., there you have code on the OnLookup trigger that won’t work if you run the table, if you run the related forms it works fine. Hope I made myself understood [;)] Nils

Hi All, The problem here is everyone trying to modify the document no. or customer no. which is a primary key, try to rename it instead of modifying it or validating it, it should work. best of luck regards

Nils, Your right. I have never noticed that before. All these years I must have always only run such code from the form, and it was only 2 days ago that I tested some code with the table only. Thank you. I’m feeling kind of stupid now. (But on the upnote, more experienced developers here were also stumped by this). Shanon

Don’t worry Shannon… first there are no stupid questions and second it worked fine with Financials (both form and table view) - looks like a special Attain bu… sorry - feature [xx(] Saludos Nils

thats true shamon all of us missed the key point never mind it was good brain storming session.