RunModal with temp table

grouic
Member Posts: 34
Hello,
I'm trying this code on a Onlookup trigger :
Table R_TempDimensionValue is temporary.
The temp table is correctly populated and displayed but the value I choose is not copyied into the code field on the main page.
NB : I tried not using a temp table by using MARKs instead on the R_DimensionValues (that is not temp). It doesn't work either.
Any suggestion ?
Thanks !
I'm trying this code on a Onlookup trigger :
Table R_TempDimensionValue is temporary.
The temp table is correctly populated and displayed but the value I choose is not copyied into the code field on the main page.
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;
NB : I tried not using a temp table by using MARKs instead on the R_DimensionValues (that is not temp). It doesn't work either.
Any suggestion ?
Thanks !
0
Answers
-
Hi grouic,
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.)0 -
Hello,
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 theIF NOT GET(Type::BU,R_DimensionValue.Code) THEN BEGIN ... by IF NOT R_myPageRec.GET(Type::BU,R_DimensionValue.Code) THEN BEGIN ...
and everything is OK now.
0 -
Hi grouic
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:The temp table is correctly populated and displayed but the value I choose is not copyied into the code field on the main page.
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions