Chapter 3. Storing Data

You should always try to store data and relate it to other data in the best possible way, as it will reduce the time spent on coding. It will also make sure that the solution you are building will be more stable and perform better.

This chapter will show you how to create tables where you can store data, how one can create relations between tables, and how to enforce referential integrity by creating unique indexes and delete actions.

You will learn about the following topics in this chapter:

  • Tables
  • Extended datatypes
  • Relations

Extended datatypes

In order to understand how data is stored in Dynamics AX 2012, you need to get an understanding of the extended datatypes.

As you have read in the previous chapter, there are certain primitive datatypes you can use when programming in AX. Primitive datatypes can be extended and with more information to help you when you program in AX. A real datatype can be extended to create a quantity or an amount field, and each extended version can have its own set of properties, for example, four decimal places might be allowed for the amount field, but quantity might be restricted to zero decimal places. If one does not use an extended datatype for quantity, one would have to set the label, help text, number of decimals, and other relevant information on all the tables where the field is used.

Extended datatypes can be extended any number of times, for example, the type quantity can be created from Real and quantity can be further extended to create PurchQuantity and SalesQuantity.

Creating an extended datatype

To create an extended datatype (EDT), open the AOT and expand the node Data Dictionary | Extended Data Types. Then right-click Extended Data Types and select New. You will then get a submenu as shown in the following screenshot:

Creating an extended datatype

The following are the different types of which you can use one as the base for your extended datatype:

,

Datatype

Information

String

A string can contain all kinds of characters and the length is decided in the properties of the EDT.

Integer

An integer can contain integer values from -2,147,483,647 to 2,147,483,647.

Date

A date can hold a date value and the value will be stored in the form 3/23/2009.

Time

A time value can hold the time of a day from 12:00:00 am to 11:59:59 pm. The value stored in the database is, however, an integer specifying the seconds after midnight, where the range spans from 0 to 86400.

UtcDateTime

This datatype combines the date and time types into one datatype. In addition, it also holds information regarding the time zone. Its value ranges from 1900-01-01T00:00:00 to 2154-12-31T23:59:59.

Enum

This datatype should always be linked to a base enum by the enum property Type.

Container

This datatype contains a list of values with different datatypes.

GUID

This datatype is a Global Unique Identifier—a number that consists of 16 bytes. It is written in text as a sequence of hexadecimal digits, for example, {5EFB37A3-FEB5-467A-BE2D-DCE2479F5211}. An example of its use in AX is the WebGUID field in the SysCompanyGUIDUsers table.

Int64

This datatype is a 64-bit integer that can contain integer values from 9,223,372,036,854,775,808 to 9,223,372,036,854,775,808.

In this example, we will use a string. To open the property window, right-click on String and select Properties.

The property window will appear as follows:

Creating an extended datatype

As you can see, some of the properties have a yellow background. This means that it is a best practice to have these properties filled out.

Also notice that if you change any of the properties that have a default value, the value entered will be bold. This is only done to make changes more visible. If you see properties with a red background, they are mandatory.

You can also see a categorized list of properties, in all property windows, by pressing the Categories tab. The categories will vary depending on what kind of element is active. The following screenshot shows the categories for the extended datatype we have created:

Creating an extended datatype

The first thing you would want to change is the name of the EDT. In our example we will call it CarId. You should also give the EDT a label that users see throughout the solution. So open the label editor by clicking on the square to the right in the Label field. Create a label with text Car Id. Do the same in the HelpText field and create a label with text Unique identifier for a record in the CarTable. The last thing you want to check now is the length of the field. By default, a string is set to 10 characters, which is fine for our example.

There will be times where you will want to check more properties as well, and if you are creating an EDT of type integer, it obviously has a different set of properties than a string, but these are just the basics.

Here is a list of some of the most used properties for all kinds of extended datatypes. Not all of the properties are explained here as that is beyond the scope of this book, so if there are properties you want to know more about that haven't been explained in this book, take a look in the developers' help file.

Property

Information

ID

ID is set by the AX core according to a number sequence for each object layer and cannot be changed by the developer.

Name

Name is the system name that you will use when writing code that references to this extended datatype.

Label

Label is the name of the field that the users will see in forms and reports.

HelpText

Help text is shown in the lower-left corner of a window when the field is active in a form.

FormHelp

FormHelp can be used to specify a specialized lookup form when the user does a lookup action on this field.

DisplayLength

DisplayLength is the maximum number of characters shown in a form or report.

Extends

Extends is used to inherit another extended datatype.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142