Often times users within Dynamics AX 2009 will need to be able to view transactional data within a form. Sometimes this transactional data changes on a very frequent basis. Within base Dynamics AX, the user will have to manually refresh the form’s data to see the most recent records. Depending on the situation (like an interface for example), it could be useful to have the data automatically refresh without the need for any user interaction. To accomplish this, the following can be implemented.

How to automatically refresh data in a form within Dynamics AX using code

1. Create two buttons, one named “Auto Refresh” and one “Manual Refresh”.
Code has been written to hide the button that was last clicked.

Dynamics AX auto refresh form data

Dynamics AX auto refresh form data

2. Overwrite clicked() on the Auto Refresh button. This code will refresh the form every minute.

void clicked()
{

AutoRefreshExample cacheRec;
int msInterval;
;

super();

msInterval = 1 * 60 * 1000; // Refresh every minute

cacheRec = AutoRefreshExample::find(AutoRefreshExample.RecId);
AutoRefreshExample_ds.research(true);
AutoRefreshExample_ds.findRecord(cacheRec);

timeOut = ButtonAutoRefresh.setTimeOut(funcName(), msInterval, false);

this.visible(false);
autoRefreshOn = buttonManualRefresh.visible(true);
}

3. Overwrite clicked() on the Manual Refresh button. This code will stop the auto refreshing.

void clicked()
{
;

super();

autoRefreshon = this.visible(false);
ButtonAutoRefresh.visible(true);

ButtonAutoRefresh.cancelTimeOut(timeOut);
}

Download Sample XPO>