Application substituted kernel classes extend system classes whose names begin with "x". They are listed at the bottom of the Classes node in the AOT. To indicate that the classes are special, their icons differ from those of the other application classes.
Most application substituted kernel classes have a global variable used to access the class. The global variables do not need a variable declaration and are pre-instantiated by the client.
Each class serves a different purpose. The extent to which you will need to use them vary.
When using the classes:
• Always use the application classes rather than using the system classes directly.
• Use the global variables to access the classes, when available.
• Never instantiate these classes (except for the Session class). Use the global variables listed below instead.
• Specify the application class name to access static methods.
Application class System class Global variable Runs on
Session xSession (none) Client and server
Application xApplication appl Server
Company xCompany appl.company Server
Info xInfo Infolog Client
ClassFactory xClassFactory classFactory Client and server
Global xGlobal (none) Client and server
VersionControl xVersionControl versionControl Client Five of these classes are described further.
xApplication
The xApplication class provides access to information about the current application. It also provides some application level functions.
The Application class extends the xApplication class, and allows its methods to be overridden.
Some of the more commonly used and overridden methods on Application are:
• buildNo() - returns the build number of the application in its current state.
• releaseVersion() - returns the release version of the application.
• company([dataAreaId]) - gets or sets the dataArea that the user is currently using.
• deleteCompany(dataAreaId) - deletes a company account indicated by the dataAreaId.
xCompany
The xCompany class provides access to information about the current company (dataArea). It also provides some application level functions.
The Company class extends the xCompany class, and allows its methods to be overridden.
Some of the more commonly used and overridden methods on Company are:
• new() - this is called when a user changes company in their client.
xInfo
The xInfo class provides access to the InfoLog framework.
The Info class extends the xInfo class, and allows its methods to be overridden.
Some of the more commonly used and overridden methods on Info are:
• add() - adds a message to the infolog, to display it to the user.
• currentAOLayer() - returns the current layer the user is working in.
• createWorkspaceWindow()- opens a new workspace window.
• createDevelopmentWorkspaceWindow() - opens a new development workspace window.
• infologData() - returns an InfoLogData container object holding the messages currently in the infolog (which could be saved or displayed somewhere other than the infolog, for example, in a log).
xGlobal
The xGlobal class provides a large selection of functions, designed to be used anywhere in the application.
The Global class extends the xGlobal class, and allows its methods to be
The static methods on Global are special in that they can be called from any place in the application, without having to specify the Global class. For example, Global::time2StrHMS() can be called as time2StrHMS(). In this way, they become more like the system functions.
xClassFactory
The xClassFactory class is used by the system to create objects from classes.
One analogy of this is, a Class is a blueprint, xClassFactory is a factory and an Object is the finished product.
The ClassFactory class extends the xClassFactory class, and allows its methods to be overridden.
Some of the more commonly used methods on ClassFactory are:
• formRunClass(args) - creates a FormRun object for a specific form design, using the formstr value in the args parameter.
• createClass(classId) - creates an object from a class Id.
• queryRunClass(args) - creates a QueryRun object for a specific query design, using the querystr value in the args parameter.
The following example demonstrates how to use ClassFactory to create and run the CustTable form using X++:
1. Create a new Args object, passing in formStr(CustTable).
2. Call ClassFactory.formRunClass() passing in the args object, and placing returned object into a FormRun variable.
3. Call the init(), run() and detach() methods on the FormRun object.
Args args;
FormRun formRun;
args = new Args(formstr(CustTable));
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
Lab 3.3 - Create a Global method
Scenario
Since your company's recent upgrade to Microsoft Dynamics AX 2012, there has been a request for a function to convert a Date type value to an equivalent
utcDateTime type value. You have been given the task of creating a new function to perform this conversion.
Challenge Yourself!
Create a global method which converts a date value to its equivalent utcDateTime value. Write a method to accept a date value and set the time component equal to midnight. Use the new global method to output the utcDateTime of a specified date to the screen using a job.
Step by Step
1. Open the AOT.
2. Find the class called Global.
3. Right-click Global class and select New > Method.
4. Copy the code shown below for the method date2utcDateTime in to the new method.
5. Save your changes to the Global class.
6. Create a new job.
7. Copy the code below for JobDate2UTC to the new job.
8. Press F5 to run the job and see the results.
public static utcDateTime date2utcDateTime(date _date) {
return DateTimeUtil::newDateTime(_date, 0);
}
static void JobDate2UTC(Args _args) {
print date2utcDateTime(mkDate(28,9,12));
pause;
}