Tuesday, December 27, 2022

How to set count on Tile using X++ (Update tile count runtime)

Set Count Value on Tiles using X++ Query

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

  1. Create an AOT query to show all the record count without the number of days filter.
  2. Create a Tile and set the below 2 properties:
    • Query: query name
    • Type: count
  3. Create a new form.
  4. Add a new Integer filter control on the form and set the auto declaration property to Yes. (No of Days)
  5. Add a new Tile button on your form and set the tile property with the above-created tile name.
  6. Override the clicked method of your Tile button and add the below code:
public void clicked() {
    #Task
    super();
    element.task(#taskRefresh);
}
  1. 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;
}
  1. 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;
}
  1. Build and synchronize your project area and check the result by modifying the Number of days filter control.

No comments:

Post a Comment

How to Post Partial Product Receipt in D365FO Using X++ Code

How to Post Partial Product Receipt in D365FO Using X++ Code How to Post Partial Product Receipt in D365FO Using X++...