In X++, classes are grouped into two main categories:
1. Application Classes
These are written in X++ and found in Application Explorer under Code > Classes
. Developers can access and customize these classes directly.
2. System Classes
Also known as kernel classes, these are internal to the platform. You can see them listed under System Documentation > Classes
in Application Explorer, but their source code is not available. For a complete list, refer to the API, class, and table references.
Structure of a Typical Application Class
A standard application class in X++ usually includes:
Class declaration and member variables: The class uses access modifiers like
public
,private
, orextends
and declares instance variables.new
method: Acts as the constructor. It’s used to create an object using thenew
keyword. Derived classes can call their parent class constructor usingsuper()
.finalize
method: Serves as a destructor by naming convention, but is not automatically triggered by garbage collection.
Other common method types include:
Instance methods
Static methods
Main methods
You can also define methods on elements like:
Classes
Maps
Views
Data Sets
Forms
Queries
Using Substitute Application Classes
For many system (x-)classes, there are corresponding application-level substitutes that extend them. These are recommended for use instead of the system classes.
System classes often have names starting with lowercase ‘x’ (e.g., xApplication
, xVersionControl
). When extended by application classes (e.g., Application
extends xApplication
), the new versions are referred to as substitute application classes.
These substitutes typically come with predefined global variables such as:
Application Class | x-System Class | Global Variable |
---|---|---|
Args | xArgs | None |
Application | xApplication | appl |
ClassFactory | xClassFactory | classFactory |
Company | xCompany | appl.company |
Global | xGlobal | None |
Info | xInfo | infolog |
MenuFunction | xMenuFunction | None |
Session | xSession | None |
VersionControl | xVersionControl | versionControl |
To call static methods, use:
Application::checkForNewBatchJobs();
To access instance members, use the global variable if available:
appl.buildNo();
Note: Not all substitute classes have global variables. For example, Session
does not.
Example: Working with Substitute Application Classes
TreeNode treeNode;
Args args;
FormRun formRun;
// Use global variable for Application
info(appl.buildNo());
// Access company-related method
appl.company().reloadRights();
// Use infolog to find a node
treeNode = infolog.findNode("\\forms\\custTable");
info(treeNode.AOTgetProperty("Name")); // Outputs: CustTable
// Launch a form using ClassFactory
args = new Args(formstr(Batch));
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
info("Method is ending. This is a message in the Infolog.");
Batch Processing Classes
To create server-based batch jobs in X++, you extend RunBase
or RunBaseBatch
. These are more secure as they execute using the permissions of the user who started them and restrict client interaction.
Enabling Server-bound Batch Execution
Override runsImpersonated()
to return true
:
public boolean runsImpersonated()
{
return true;
}
Only use the following methods from Info and Global classes:
add
Info.copy
,cut
,import
,export
,line
,num
Global::error
,info
,warning
Hiding the Recurrence Button
Use the Args.parmEnum
method with NoYes::Yes
to hide the Recurrence button in batch dialogs.
Example:
static void noRecurrenceButton(Args _args)
{
Args a;
InventTransferMultiShip inventTransferMultiShip;
a = new Args();
inventTransferMultiShip = InventTransferMultiShip::construct();
a.caller(inventTransferMultiShip);
a.parmEnum(NoYes::Yes);
BatchDialog::main(a);
}
Image Handling Classes
X++ includes classes to handle graphics:
Image – Work with single images: capture, rotate, crop, etc.
Imagelist – Manage collections of images with shared properties like size or transparency.
Query Object Model
X++ uses object-oriented query classes to define and execute queries programmatically. This model includes:
Class | Description |
---|---|
QueryRun | Runs the query and retrieves records. |
Query | Holds top-level structure and properties of a query. |
QueryBuildDataSource | Represents a data source; multiple can exist per query. |
QueryBuildFieldList | Specifies fields to be retrieved. Supports aggregates like SUM, AVG. |
QueryBuildRange | Defines filters (WHERE clauses) on fields. |
QueryBuildDynalink | Establishes dynamic links to parent data sources. |
QueryBuildLink | Defines joins between data sources. |
You can also use SysDa API as an alternative to create queries.
System Classes Overview
System class source code is hidden and they offer limited extensibility. They may contain:
Static or instance methods
Setters (like
LeftMargin
)
You can use them to extend built-in functionality, such as customizing forms or reports. However, they aren’t meant to be used as base templates for new development.
Additional Class Types
Collection Classes
Support for data structures like lists, maps, arrays, sets, and structs.
Application Object Classes
These control how forms and other objects behave when you build them in Application Explorer. For example, layout definition is handled by the FormDesign
class.
Integration Classes
Enable system integration:
COM – Communicates with COM objects.
DLL – Calls Windows DLL functions.
IO – Reads/writes to external files.
ODBCConnection – Connects to external databases using ODBC.