The requirement of the form I created is to display the information for the customers' activities along with its monthly sales data.
In order to accomplish this:
- I first created a temporary table setting its table type property to TempDB.
- Added my termporary table as datasource into my form.
- Override my form's datasource method init.
The code of the init method.
[DataSource]
class MyTableTmp
{
public void init()
{
myClass = new MyClass();
super();
tempTable = myClass.populateTempTable();
MyTableTmp.linkPhysicalTableInstance(tempTable);
}
}
The object my class refers to a class I created that handles the business logic to insert records into my temporary table.
This is code for the class method.
public MyTableTmp populateTempTable()
{
MyTableTmp tempTable;
smmActivities activityTable;
smmActivityParentLinkTable linkTable;
while select activityTable
join linkTable
where linkTable.ActivityNumber == activityTable.ActivityNumber
&& linkTable.ParentType == smmActivityParentType::Customer
&& activityTable.DataAreaId == curExt()
{
CustTable custTable = CustTable::findByRef(activityTable.DataAreaId, linkTable.RefRecId);
tempTable.ActivityNumber = activityTable.ActivityNumber;
tempTable.ActivityTypeId = activityTable.TypeId;
tempTable.RepsonsibleWorker = HcmWorker::find(activityTable.ResponsibleWorker).name();
tempTable.CustAccount = custTable.AccountNum;
tempTable.Name = custTable.name();
tempTable.MySales = this.calcMySales(custTable);
tempTable.insert();
}
return tempTable;
}
Lastly, I added a custom filter in my form that allows the user to select the month. Then, I pass the month selected as a parameter into my class so it can calculate the average monthly sales of the customer and inserts that data into my temporary table.
Every time that I select a different month an event handler, added into my class, is triggered so that it calls my form's datasource executeQuery method in order to first delete the table and then repopulate it again.
My form's filter event handler method:
[FormControlEventHandler(formControlStr(MyForm, MonthFilter), FormControlEventType::Modified)]
public static void MonthFilter_OnModified(FormControl sender, FormControlEventArgs e)
{
FormDataSource fds = sender.formRun().dataSource("MyTableTmp") as FormDataSource;
if (fds)
{
fds.executeQuery();
}
}
The code for the executeQuery method.
[DataSource]
class MyTableTmp
{
public void executeQuery()
{
int monthSelected = MonthFilter.selectionChange();
delete_from tempTable;
myClass.parmMonthsOfYear(monthSelected);
tempTable = myClass.populateTempTable();
super();
}
}
I researched and tried out all solutions posted in the following links but none of them have worked out for me.
I do recall back when I was programming in AX 2012 that it worked populating the contents of a form's grid that uses a temporary table.
I kindly request your help to let me know both what I'm doing wrong and what I'm missing.