In so many cases when writing code for Dynamics NAV you want to display a dialog to notify the user or open a progress dialog.  Today, we always need to consider that the code might be running from a web service where the GUIALLOWED variable is set to false.

I created a codeunit to replace the dialog variable type in my code.  That codeunit is attached at the end.  This saves me work and the code is quite simple.
[code htmlscript=”false”]Customer – OnPreDataItem()
DialogInstance.WindowOpen(
‘Reading Customer #1##################\\’ +
‘@2@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@’);
DialogInstance.WindowSetTotal(2,COUNT);

Customer – OnAfterGetRecord()
DialogInstance.WindowProcess(2);
DialogInstance.WindowUpdateText(1,"No.");

Customer – OnPostDataItem()
DialogInstance.WindowClose;[/code]
The Dialog Instance codeunit checks if a dialog can be opened and only updates the progress dialog ten times per second.
[code htmlscript=”false”]WindowProcess(WindowIndex : Integer)
IF NOT GUIALLOWED THEN
EXIT;

Counter[WindowIndex] := Counter[WindowIndex] + 1;

IF NOT DialogIsOpen THEN
EXIT;

IF (CURRENTDATETIME – WindowLastUpdated) > 100 THEN BEGIN
Window.UPDATE(WindowIndex,ROUND(Counter[WindowIndex] / Total[WindowIndex] * 10000,1));
WindowLastUpdated := CURRENTDATETIME;
END;[/code]
DialogInstance

One thought on “Dialog in Dynamics NAV

  1. Bogdan says:

    On my progress bar, the value (ecs 25%) isn’t updating in sync with the bar itself…so when the percentage is at 50%, the bar is only at 25%…any help?

Leave a Reply

%d bloggers like this: