Build better business applications with NAV
The reader would benefit by reading the previous article on Microsoft Dynamics NAV 2009: Designing Forms
EXIT(CurrForm.MatrixBox.MatrixRec.”No.”);
ItemLedgerEntry.RESET;
ItemLedgerEntry.SETCURRENTKEY(“Source Type”, “Source No.”,
“Item No.”, “Variant Code”, “Posting Date”);
ItemLedgerEntry.SETRANGE(“Source Type”, ItemLedgerEntry.”Source
Type”::Customer);
ItemLedgerEntry.SETRANGE(“Source No.”, “No.”);
ItemLedgerEntry.SETRANGE(“Item No.”,
CurrForm.MatrixBox.MatrixRec.”No.”);
ItemLedgerEntry.SETRANGE(“Entry Type”, ItemLedgerEntry.”Entry
Type”::Sale);
IF ItemLedgerEntry.FINDSET THEN
REPEAT
ItemLedgerEntry.CALCFIELDS(“Sales Amount (Actual)”);
TotalSales := TotalSales + ItemLedgerEntry.”Sales Amount
(Actual)”;
UNTIL ItemLedgerEntry.NEXT = 0;
EXIT(FORMAT(TotalSales));
A matrix form consists of two tables and some calculation based on those two tables. One set of records runs vertically along the left-hand side of the matrix box while the other set runs horizontally across the top. A grid is displayed on the rest of the form displaying a calculated value. We’ll examine each of these pieces individually.
We begin by creating a normal form that is bound to the Customer table. For this special form we add a matrix box control. The left-hand side operates exactly the same as a standard list form. It will display all of the customers and there will be a scrollbar to look through the list. As we don’t want the user to change anything on this form, we set the Editable property of the matrix box to No. We will also have to write code that refers to this control so we must give it a name.
Also, the matrix box itself operates on a table. In this case it is the Item table. As there is so much data stored in a table, we have to tell the control what we want to see. That’s why we add a textbox as a column header to the top of the form. The source expression for that textbox is the ColumnHeader method. Let’s take a look at the code there.
EXIT(CurrForm.MatrixBox.MatrixRec.”No.”);
CurrForm is the current form. MatrixBox is the value in the name property of our matrix box control. MatrixRec is the record in the matrix box that we are referring to (just like rec on a normal form). Finally, No. is the field from the MatrixSourceTable property(in this case the Item No). So our column headers will just be the Item Number from the Item table.
Lastly, we have to tell the form how to calculate the data we want to see. We add another textbox to the form and give it a source expression of CalculateData, which is a function on our form. This function could return anything, but in our case it returns the amount a customer has spent on a specific item. Let’s take a look at the important code that combines the data from both tables.
ItemLedgerEntry.SETRANGE(“Source No.”, “No.”);
ItemLedgerEntry.SETRANGE(“Item No.”,
CurrForm.MatrixBox.MatrixRec.”No.”);
The Item Ledger Entry table already has fields that refer to the Customer table and to the Item table. The first filter uses the No. field from the source table (Customer). The second filter determines the current Item Number from the matrix box and uses it. Later in the function, a number is calculated and returned as a text variable.
In this part of the article series we covered:
In the next part we will create wizard-style form.
Further resources on this subject:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…