Using the Infolog System
The Infolog system is a dialog system that displays information, warning, and error messages.
The Infolog is updated on screen just before user input is accepted.
Add your own information using the following methods:
-
info()
-
warning()
-
error()
-
checkFailed()
Use the setprefix() function to create headings within the Infolog.
Info, warning and error are methods on the Global application class.
Each method takes three arguments:
-
a string that is added to the log
-
a path to the Microsoft Dynamics AX internal Help system that can be used to open the Help viewer and present a longer, explanatory text. This argument is optional.
-
an Infolog action that can be used to initiate an action, for example start the X++ editor. This argument is optional.
To initiate an action, create a class that extends the SysInfoAction class. The SysInfoAction_Editor class is an example of how this is done. The class can be used to start the editor.
The methods return an error exception code in the Infolog. The Infolog displays different icons for the three types of information.
|
|
Information. |
|
Information with a Help page attached. |
|
Information with an action attached. |
|
|
Warning. |
|
Warning with a Help page attached. |
|
Warning with an action attached. |
|
|
Error. |
|
Error with a Help page attached. |
|
Error with an action attached. |
Example
boolean journalCheckTrans(WMSJournalTrans _WMSJournalTrans)
{
InventMovement inventMovement;
InventDimParm inventDimParm;
InventUpd_Registered inventUpd_Registered;
boolean ok = true;
;
if (!super(_WMSJournalTrans))
return false;
setPrefix(strfmt("@SYS14077", _WMSJournalTrans.itemId));
if (_WMSJournalTrans.qty == 0)
{
warning("@SYS16660");
return ok;
}
// More code lines - not included in the example...
return ok;
}
Using throw before any of the three methods will terminate the execution.
Example
setprefix(funcname());
throw error(strfmt("Unknown type: %1",typeof(_Value)));
CheckFailed
The checkFailed method on the Global application class returns a boolean and is used for warnings.
Like info, warning and error, checkFailed takes three arguments:
-
a string that is added to the log
-
a path to the Microsoft Dynamics AX internal Help system that can be used to open the Help viewer and present a longer, explanatory text. This argument is optional.
-
an Infolog action that can be used to initiate an action. This argument is optional.
setprefix
The system function setprefix is used to give a heading for the information, warning, or error presented in the Infolog.
The text is automatically pushed and popped from the execution stack. This means that if you use setprefix several times within the same block of code, the headings are automatically indented. When leaving a block, the heading is automatically set to the previous level.
Use the small example below to see the automatic indents in the Infolog:
static void testJob(args a)
{
int i;
;
setprefix('heading');
setprefix('a');
for (i=1; i<=10; i++)
{
setprefix(int2str(i));
error('test');
}
}
Note |
|---|
|
Use labels rather than text strings in connection with the setprefix function. |
Use infolog.errorsPerBatch to set the maximum number of errors under one heading (headings are created using the setprefix system function). If the actual number of errors exceed the maximum, a text is displayed saying that there may be more errors than the those presented.
This is for example used by SysExportImport.importData that is activated during data import: #define.errorsPerBatch(10).
Use the line limitation if a large number of errors may be generated, and all the user needs to know is that an error has occurred.
You do not have to reset the value afterwards.
Note