Announcements
No record found.
Hello everyone, I hope you're doing well.
I'm a beginner in programming and currently facing an issue with a grid that should display data from an InMemory table in a form.
The goal is to have a form with two fields: Start date and End date, plus a "Calculate" button. When I click the button, I want the grid to display the sum of invoice line amounts per item, within the selected date range.
So far:
info()
But... the grid remains empty.
When I check the table browser in another tab right after clicking the button, the InMemory table is still empty. I’m not sure if the problem comes from the data not being inserted in the table, or if the grid isn’t displaying it properly.
I really don’t know what I’m missing.
Here’s what I’ve done:
[Form] public class TESTJBB11 extends FormRun { FormDateControl startDateCtrl; FormDateControl endDateCtrl; /// <summary> /// Initializes the form and binds the date controls. /// </summary> public void init() { super(); // Link the form controls to class variables using their names from the designer startDateCtrl = element.design().controlName("StartDateControl"); endDateCtrl = element.design().controlName("EndDateControl"); } [Control("Button")] class CalculateButton { /// <summary> /// Calculates the total invoice line amount per item between two selected dates. /// The result is inserted into an InMemory table displayed by the form grid. /// </summary> public void clicked() { super(); Map itemMap = new Map(Types::String, Types::Real); // To accumulate totals per ItemId CustInvoiceTrans invoiceTrans; TmpSalesInvoiceSumJBBTEST tmpBuf; TransDate startDate = startDateCtrl.dateValue(); TransDate endDate = endDateCtrl.dateValue(); // Validate date fields if (!startDate || !endDate) { error("Please enter both a start and end date."); return; } // Access the form datasource for the InMemory temporary table FormDataSource ds = element.dataSource("TmpSalesInvoiceSumJBBTEST"); // Clear any existing data from the datasource (grid) ds.executeQuery(); // Refresh buffer ds.delete(); // Delete all existing records from the view ttsbegin; // Select invoice lines between selected dates while select ItemId, LineAmount, InvoiceDate from invoiceTrans where invoiceTrans.InvoiceDate >= startDate && invoiceTrans.InvoiceDate <= endDate { real existingSum = itemMap.exists(invoiceTrans.ItemId) ? itemMap.lookup(invoiceTrans.ItemId) : 0; itemMap.insert(invoiceTrans.ItemId, existingSum + invoiceTrans.LineAmount); } // Insert aggregated data into the datasource (so it will appear in the grid) MapEnumerator mapEnumerator = itemMap.getEnumerator(); while (mapEnumerator.moveNext()) { tmpBuf.clear(); tmpBuf.ItemId = mapEnumerator.currentKey(); tmpBuf.AmountSum = mapEnumerator.currentValue(); ds.cursor().clear(); ds.cursor().data(tmpBuf); ds.create(); // Log inserted item for debugging info(strFmt("Inserted ItemId: %1, AmountSum: %2", tmpBuf.ItemId, tmpBuf.AmountSum)); } ttscommit; // Refresh the grid to display the new data ds.executeQuery(); } } }
Thanks in advance for your help!
tmpSalesInvoiceSumJBBTEST.ItemId = 'item1' tmpSalesInvoiceSumJBBTEST.AmountSum = 42; tmpSalesInvoiceSumJBBTEST.insert();
while select sum(LineAmount), ItemId, LineAmount from invoiceTrans group by ItemId where invoiceTrans.InvoiceDate >= startDate && invoiceTrans.InvoiceDate <= endDate
[Form] public class TESTJBB11 extends FormRun { FormDateControl startDateCtrl; FormDateControl endDateCtrl; /// <summary> /// Initializes the form and binds the date controls. /// </summary> public void init() { super(); // Link the form controls to class variables using their names from the designer startDateCtrl = element.design().controlName("StartDateControl"); endDateCtrl = element.design().controlName("EndDateControl"); } [Control("Button")] class CalculateButton { /// <summary> /// Calculates the total invoice line amount per item between two selected dates. /// The result is inserted into an InMemory table displayed by the form grid. /// </summary> public void clicked() { super(); TransDate startDate = startDateCtrl.dateValue(); TransDate endDate = endDateCtrl.dateValue(); if (!startDate || !endDate) { error("Please enter both a start and end date."); return; } // Clear existing records from the data source buffer delete_from TmpSalesInvoiceSumJBBTEST; // Use SQL grouping directly in the select statement CustInvoiceTrans invoiceTrans; while select sum(LineAmount), ItemId from invoiceTrans group by ItemId where invoiceTrans.InvoiceDate >= startDate && invoiceTrans.InvoiceDate <= endDate { TmpSalesInvoiceSumJBBTEST.ItemId = invoiceTrans.ItemId; TmpSalesInvoiceSumJBBTEST.AmountSum = invoiceTrans.LineAmount; TmpSalesInvoiceSumJBBTEST.insert(); info(strFmt("Inserted ItemId: %1, AmountSum: %2", TmpSalesInvoiceSumJBBTEST.ItemId, TmpSalesInvoiceSumJBBTEST.AmountSum)); } // No need to call executeQuery() — the table will refresh automatically } } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Giorgio Bonacorsi 658
André Arnaud de Cal... 468 Super User 2026 Season 1
Syed Haris Shah 333 Super User 2026 Season 1