Thursday, December 26, 2013

How to make your ProgressBar progress on server

In AX 2012 we deal with three types of progress bars:

  • SysOperationProgress
  • SysOperationProgressEmbedded
  • SysOperationProgressServer
that initialized in RunBase.progressInit method.

What concerns the latter that runs on the server side for batch jobs and tasks, I have never seen before that the Progress field changed during batch tasks execution. 

This is because RunbaseProgress Construct method is called without _disableProgressWithoutGUI parameter; nevertheless, it exists in its own New method. This parameter is always TRUE.

I do not know if this option is disabled by purpose having some other developing perspectives in mind, or simply by mistake.

In fact, it is not enough just to extend constructors accordingly to pass this parameter from your own processing class down to SysOperationProgressServer methods. There is another bug in Construct.

This bug does not take into account the caller class that creates its progress bars passing an empty GUID, so that Update method always refreshes the first progress bar found in SysProgress table. In other words, if you started a few batch tasks simultaneously, you will see an interesting progressing: after 100% it starts from zero and so on until the last task finishes. No progressing for the rest of the tasks.

The third bug is in Reset method, which actually run in turn by progress.Kill method (now marked as obsolete). Unfortunately, I do not inderstand the logic of this approach to reset the progress bar when my tasks is finished. From my point of view, it must be really 'killed' it in the end.

All in all, the following changes in forementioned objects fix the problem.