Set Count Value on Tiles using X++ Query
Dear All,
Today, we will explore how to set the count value on Tiles using an X++ query. I encountered this scenario during a recent customization project. This technique is particularly useful when you need to filter the tile data count based on an unbound control on the form, where the control's value is not associated with any of your dataSource columns.
Requirement
Add an Integer control on the form and upon modification of that control, update the count of the Tile with the condition of records created before a given number of days.
Logic
((today's date - Created Date) > number of days given in the control)
then show on the count otherwise not.
Implementation Steps
- Create an AOT query to show all the record count without the number of days filter.
- Create a Tile and set the below 2 properties:
- Query: query name
- Type: count
- Create a new form.
- Add a new Integer filter control on the form and set the auto declaration property to Yes. (No of Days)
- Add a new Tile button on your form and set the tile property with the above-created tile name.
- Override the clicked method of your Tile button and add the below code:
public void clicked() {
#Task
super();
element.task(#taskRefresh);
}
- Override the getData method of your Tile button and add the below code:
public TileButtonControlData getData() {
TileButtonControlData ret;
ret = super();
if (FilterNoOfDays.value() != 0) {
int recordCount = element.countFromQuery(queryStr(TestTilePOLInes));
ret.strTileData(any2Str(recordCount));
}
return ret;
}
- Add a new method on the form level with the below code to get the count from the query with the No of days condition:
public Integer countFromQuery(str _query) {
int totalRecords;
Query query = new Query(_query);
QueryRun qr = new QueryRun(query);
while (qr.next()) {
TESTAllPOLinesView dsTest = qr.get(tablenum(TESTAllPOLinesView));
int dateDiff = today() - DateTimeUtil::date(dsTest.CreatedDateTime1);
int filterValue = FilterNoOfDays.value();
if (dateDiff > filterValue) {
totalRecords++;
}
}
return totalRecords;
}
- Build and synchronize your project area and check the result by modifying the Number of days filter control.