Print Statements
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
X++ provides a print statement that allows you to display text or selected results in a temporary window. The messages are displayed in a Print window that appears when the first print statement is executed.
The print statement can be a convenient alternative to the Global::info method during testing. The info method displays text in the Infolog window. The following table compares the print statement against the Global::info method.
Feature |
Print statement |
Info method |
---|---|---|
Ease of invocation |
The Print statement automatically converts various data types to strings. It can convert multiple data types in one invocation. |
The Info method requires that the input parameter be a string. |
Copy to clipboard |
The Print window contents cannot be copied to the clipboard. |
Infolog contents are easily copied to the clipboard. |
Scope of lifetime |
The Print window closes when the X++ job ends. Therefore, always write a pause statement at the end of the job, whenever a print statement occurs in the job. Otherwise the Print window contents will display too briefly to be read. The pause statement displays a dialog with buttons labeled Yes and No. Click Yes if the job should continue beyond the pause statement. |
The Infolog window persists for the whole client session. |
Size and location |
The Print window can be a specific size, and in a specific location on the screen. For example, consider the following X++ window at statement: window 55,4 at 22,3; The following list explains the meaning of each numeric parameter:
|
The Infolog window is sized and placed by the system. |
Common usage |
The Print statement is used for convenience during testing. It can help you debug small problems without needing to run a formal debugger. |
The Info method is appropriate for use in production. |
X++ Code Example
The following X++ job demonstrates that the print statement automatically converts any data type to a string. To create a job in the AOT, right-click the Jobs node, and then click New Job.
static void PrintJob2(Args _args)
{
str s1 = "Hello";
int n2 = 42;
utcDateTime udt3 = DateTimeUtil::utcNow();
Dialog dlog4 = new Dialog();
window 55,4 at 22,3;
print "The print statement automatically converts data types to strings.";
print s1, " -- ", n2, " -- ", udt3, " -- ", dlog4;
pause;
Global::info("User clicked 'Yes' to continue to this call to info.");
info(int2Str(n2)); // int2Str converter is needed.
}
/*** Output to the Print window:
The print statement automatically converts data types to strings.
Hello -- 42 -- 10/3/2011 09:18:10 pm -- 1
***/
/*** Output to Infolog window:
Message (02:18:10 pm)
User clicked 'Yes' to continue to this call to info.
***/
See also
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.