Home› X++ Programming Language› / Programs / Hello World using info()
🚀 Programming Example

Hello World using info()

40 Views
Beginner
Code Snippet
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

/// <summary>
/// Hello World using info().
/// </summary>
internal final class XppHelloWorld
{
    public static void main(Args _args)
    {
        info(""Hello World"");
    }
}

📘 Explanation

Hello World using info()
Figure: Hello World using info()

Hello World using info() in X++

Overview

Every programming journey starts with "Hello World", and X++ is no different. This program writes the text Hello World to the Infolog, the message bar that Dynamics 365 Finance and Operations (D365 F&O) shows at the top of the browser. It looks very small, but it teaches three core ideas you will use in every X++ program: how a runnable class is structured, how the main() method acts as the entry point, and how info() sends a message to the user.

In older versions (Dynamics AX 2012) developers wrote quick tests as Jobs. In D365 F&O, Jobs no longer exist. They are replaced by runnable classes, which are normal classes that contain a static main() method.

Prerequisites

  • A D365 F&O development VM (or Unified Developer Environment) with Visual Studio.
  • A model and a project. In the project, choose Add > New Item > Dynamics 365 Items > Code > Runnable Class (Job).
  • No tables or setup data are needed. This program only prints text.

Code Walkthrough

1. The documentation header

/// 
/// Hello World using info().
/// 

The three lines starting with /// are an XML documentation comment. The compiler ignores them, but Visual Studio shows the summary as a tooltip wherever the class is used, and best-practice checks warn when public classes have no summary. Adding it from your first program builds a good habit.

2. The class declaration

internal final class XppHelloWorld
  • internal: the class can be used only inside its own model. Test and demo classes should not be visible to other models.
  • final: no other class can extend it. A runnable demo class has no reason to be inherited.
  • XppHelloWorld: the class name. It must match the element name in the AOT, and a common prefix (here Xpp) avoids name clashes with standard Microsoft objects.

3. The entry point

public static void main(Args _args)

When you run a class, the runtime looks for a method with exactly this signature. It is static because no object exists yet when the class starts. The Args parameter carries information about the caller, such as the record selected on a form or the menu item that started the class. This program does not use it, but the parameter must still be declared. The leading underscore in _args follows the X++ naming convention for parameters.

4. Printing the message

info("Hello World");

info() is a global function that adds an information message to the Infolog. The text appears in the message bar after the code finishes. Every statement in X++ ends with a semicolon.

Key Concepts

  • Runnable class: any class with public static void main(Args _args). It replaces the AX 2012 Job.
  • Infolog: the user message system of D365 F&O. It supports three levels: info() (blue), warning() (yellow) and error() (red).
  • Access modifiers: public, internal, protected and private control who can use a class or method.
  • Running the class: right-click the class > Set as Startup Object, then press Ctrl+F5. You can also open the browser URL ?mi=SysClassRunner&cls=XppHelloWorld.

Expected Output

Hello World

The message appears in the Infolog bar at the top of the D365 F&O page. Click the message to open the full Infolog pane.

Best Practices and Common Mistakes

  • Do give the file and the class the same name. A mismatch is a common reason a runnable class "does nothing".
  • Do use labels (for example info("@MyModel:HelloWorld")) for user-facing text in real solutions so it can be translated. Hard-coded text is fine for practice.
  • Do not forget to build the project before running. The browser runs the last compiled version, not the code in the editor.
  • Do not remove the Args _args parameter. Without the exact signature, the class is not recognised as runnable.
  • Remember that the Infolog has a limit of about 10,000 lines. Avoid calling info() inside very large loops in production code.

Interview Questions

  1. What replaced Jobs in D365 F&O?
    Runnable classes: classes with a public static void main(Args _args) method.
  2. Why is main() static?
    Because the runtime calls it before any instance of the class exists.
  3. What is the difference between info(), warning() and error()?
    They write messages of different severity to the Infolog. error() only shows a message. To stop execution, use throw error("...").
  4. What is the purpose of the Args class?
    It passes context between objects, for example the caller form, the selected record (_args.record()) or a parameter string (_args.parm()).
  5. How can you run a class directly from the browser?
    With the URL parameter mi=SysClassRunner&cls=ClassName.
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.