Update a field on table from multiple fields from another table using a condition?
Tiwaz
Member Posts: 98
Hi guys.
Lets say I need to fill a field "Values" on Table1 to be like this:
"Values" = Text1 + Text2 + Text3 + ... + TextN.
Where Text1...etc are fields in another table, Table2.
Table1 and Table2 have one common field, lets call it "Key" where there can be same values of this field in both tables.
How and where should I put a code for this.
I tried to place this code OnAfterGetRecord trigger of Table1 but it doesn't work
Table2.SETRANGE ("Key","Key");
Values :=' ';
IF Table2.FIND ('-') THEN
REPEAT
Values := Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
UNTIL
Table2.NEXT = 0;
Lets say I need to fill a field "Values" on Table1 to be like this:
"Values" = Text1 + Text2 + Text3 + ... + TextN.
Where Text1...etc are fields in another table, Table2.
Table1 and Table2 have one common field, lets call it "Key" where there can be same values of this field in both tables.
How and where should I put a code for this.
I tried to place this code OnAfterGetRecord trigger of Table1 but it doesn't work
Table2.SETRANGE ("Key","Key");
Values :=' ';
IF Table2.FIND ('-') THEN
REPEAT
Values := Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
UNTIL
Table2.NEXT = 0;
0
Best Answer
-
Do you really need this as a field in Table 1?
Something like that is normally only used for display purposes and not for filtering so if that is the case then I would create a function in table 1 which goes through the records in table 2 with the same key field and concatenates the values as required and then returns this text. The value can then be shown on page/form/report as required simply by calling the function.
BTW the reason you are only getting the values from the first table 2 record is that you are rebuilding the value for each iteration of the loop. Instead of...Values := Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
...it should be...Values := Values + ' ' + Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
5
Answers
-
It seems table1.Modify Is missing after assigning to field Values?0
-
-
can you try moving code to OnAfterGetCurrRecord without modify..
and Currpage.update(FALSE)0 -
Now it only shows me the first value from the first line.

Those values are Country Code and Country Name from that Table2.
It needs to read these if they have same "key" as on Table1.
ex.:
Table2:
Key: A1
C.Code: BE
Name:Belgium
Key: A2
C.Code: GB
Name:Great Britain
Key: A1
C.Code: SI
Name:Slovenia.
And if there is a "key": A1 on Table 1,
I need to show there:BE-Belgium, SI-Slovenia,... from table 2
But it only shows first one: BE-Belgium0 -
and what if you move to previous trigger without modify and update..0
-
Same thing happens
0 -
Do you really need this as a field in Table 1?
Something like that is normally only used for display purposes and not for filtering so if that is the case then I would create a function in table 1 which goes through the records in table 2 with the same key field and concatenates the values as required and then returns this text. The value can then be shown on page/form/report as required simply by calling the function.
BTW the reason you are only getting the values from the first table 2 record is that you are rebuilding the value for each iteration of the loop. Instead of...Values := Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
...it should be...Values := Values + ' ' + Table2.Text1 + ' ' + Table2.Text2 + ' ' + Table2.Text3;
5
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
- 322 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
