Classes dictionaries

This document describes how a class can be declared by filling the class dictionary. This is a global description explaining how a class can be declared before it is used. A detailed description of the class dictionary can be found in Workbench reference Class Management.

Global Information Methods and Operations Mapping Miscellaneous Class Validation Collections Properties

In Sage X3, a function designed with version 7 supervisor tools manages data classes. A class is a data structure managing properties and behaviors.

Creating a class is performed in the class dictionary. After a class is declared, it can be instantiated to be used. If the class instance is called CLASSINST, the property PROP1 of the instance will be accessed with the CLASSINST.PROP1 syntax.

A class is defined with the following characteristics:

1. Global Information

  • A name for a persistent class is the same as the main table storing data associated with instances of the class.
  • An activity code and a module on Sage X3 dictionaries.
  • A searchable check box used to define if the search engine has to update indexes to be able to search information in the data associated with the class instances. After the check box is selected, you can select the property considered for indexing by selecting the dedicated column in the Properties tab.
  • A list of collection codes if needed. These collection codes are associated either with a set of single properties that have several values stored in an array, or with a child class when multiple child instances are associated with a main instance (for example, lines of a document).

This section describes the type of class that defines how the class is managed. It can use the following values: Persistent, Basic, Interface, Technical, and System. The following table summarizes the different characteristics of these classes:

Type of class CRUD methods available GET / CONTROL / PROPAGATE methods (also called accessors) available on properties Can methods and operations be defined? Snapshot management Comment
Persistent Yes Yes Yes Yes, automatic Associated to a main table
Interface Yes Yes Yes Yes, but has to be managed by developer code Used for CRUD-like operation on data not persisted in database (for example, logfile and processes in memory)
Basic No Yes Yes Yes, but has to be managed by developer code Used for child classes of persistent classes when the CRUD code is managed by the parent class
Technical No No Yes No
System No No No No For public classes: only direct access to properties is possible

In every class definition, there is also a grid in which a collection of ordered scripts files can be entered. These scripts files are used by the development partners to add business logic to default logic involved by the class definition. Two dedicated labels, called $PROPERTIES and $METHODS, are invoked in these scripts (in the rank order of the scripts). This is the event mechanism that gives to standard, vertical, and specific code developers the ability to add dedicated code on a list of events (defined by the value of a variable called ACTION). For detailed information, see Developer Guide Classes Events.

2. Methods and Operations

On persistent or interface classes, standard methods are supported by the supervisor. This includes the CRUD methods creation, read, update, and delete. For the persistent classes, the corresponding code can be generated and called by the supervisor layers if the corresponding check boxes have been set in the classes dictionary. These standard methods are defined in a dedicated section.

Other methods can be added, but will require additional code to be written for execution. Another section in the dictionary describes these methods as well as operations associated with the class.

Operations are described in the same manner as methods, but they also require additional information as there is no context when they are called (at least, the information needed to create and feed an instance of the class to perform the operation requested).

3. Mapping

It defines how the CRUD operations, if they exist, are linked to the database tables for the main instance of the class, and the instances of child classes.

For every database table, you can define whether the code supporting the CRUD operation is created at validation time and are automatically called (check boxes are available for every method).

4. Miscellaneous

This defines filtering options on data set managed by the class.

5. Class validation

After a class is created, the validation of the class will automatically generate codes that make the use of the class possible. The code is generated in a script file named 'C_classname.stc', where classname is the class name.

The code associated with methods used or operations in the class is generated in this script file, but includes a Gosub $PROPERTIES or Gosub $METHODS call to events. The different values for ACTION are provided in Developer Guide Classes Events.

6.Collections

In a class, collections can be defined when properties have multiple value occurrences. A collection can be associated to a list of fields or to a reference to a child instance. When a collection is associated to a list of fields, an intermediate class instance is created with the name of the collection. The individual fields present in the collection cannot have the same name as the collection.

For example, if in a class instance called 'CLASSINST', a collection called 'DISCOUNT' includes two fields (a numerical field called 'RATE' and a char field called 'PAYTERM'), an intermediate 'DISCOUNT' instance will be created, and the 3rd. rate will be accessed with the following syntax:

CLASSINST.DISCOUNT(3).RATE

If the collection corresponds to an array of children instances, the name of the collection and the name of the property that stores the array of instance must be the same. In the class dictionary, it means that the column Property and the column Collection must have the same value for the line that defines the child instance.

7.Properties

A class includes properties that can be simple fields, references to other entities usually managed by classes, or child classes instances. All these elements can also be a member of a collection. The difference between a reference and a child class is the following:

  • A reference is a property that references another entity. It is implemented through a data type that refers to a class. In the property grid, the data type code is filled, but the class code remains empty. This type of property stores a key that gives access to the data. For example, a customer code in a sales order header, or an item reference in a sales order lines are references.
  • A child class instance is a set of properties included in the main class. The CRUD operation performed on the main class operates on the child classes. To set up a child class in the Property grid line, a class code is present and the data type code remains empty. For example, a billing address in an invoice, or a sales order line in a sales order.

Any property associated with a collection code is implemented as a child class.

  • When a class code is defined on the line, we have a collection of child instances and the class is described in the dictionary.
  • When no class code is provided, we have a collection of simple fields or references. At validation time, an intermediate class description is automatically generated as an STC file. No description of this intermediate class exists in the class dictionary. The fields of the collection are members of this class, and a property called as the collection code provides access to the instance of the collection.

Child classes can be defined with four different relation types:

Relationship typeCollection characteristicsArray methods (ADDLINE, ADELLINE) availableComments
(0,1)Minimum= 0 and Maximum= 1YesThe property is an instance of a class
(1,1)No collection codeNo
(0,N)Minimum= 0 and Maximum= N. If N is 0, N can be unlimitedYesTwo things can happen:
1) The property is an instance of a class.
2) The property is a member of a set of properties with the same collection code. This collection is implemented as a technical class instance identified by the collection code.
(1,N)Minimum= 1 (or more) and Maximum= N.
If N is 0, N can be unlimited
YesThe supervisor does not control whether a line is present.
Two things can happen:
1) The property is an instance of a class.
2) The property is a member of a set of properties with the same collection code. This collection is implemented as a technical class instance identified by the collection code.

From a user interface view, a collection of properties is presented with the following rules:

  • If Minimum = Maximum, all the lines are displayed
  • Else if the property storing the number of lines exists, its value is used to define the number of lines displayed
  • Else the lines are displayed until the first empty line (all properties empty).