Chapter 3: Introduction To C/Al Programming: Training Objectives
Chapter 3: Introduction To C/Al Programming: Training Objectives
Chapter 3: Introduction To C/Al Programming: Training Objectives
Page 145
Microsoft Navision Development I − C/SIDE Introduction
C/AL Programming
This section discusses Microsoft® Business Solutions−Navision® programming
language and our development environment. You become familiar with creating
variables using the Pascal-based language and Microsoft Navision's built in
functions to run simple code. This provides a good base in preparation for
attending the Solution Developer class. The following topics are presented in this
section:
C/AL
Definition
C/AL (Client Application Language) is the programming language used in the
Client / Server Integrated Development Environment (C/SIDE) included with
Microsoft Navision.
Page 146
Chapter 3: Introduction to C/AL Programming
Where is it Used?
C/AL programming can be found in any Microsoft Navision application object.
In fact the codeunit application object is used only for programming. If you go
into the Object Designer, press the Codeunit button, select a codeunit and press
the Design button, you immediately see the C/AL editor and programming
language statements (also known as "C/AL statements", or just "code").
Other objects can have C/AL statements as well, although they do not always
have them. This code is found in "triggers" within the object. Please start
Microsoft Navision and follow along as we explore.
Page 147
Microsoft Navision Development I − C/SIDE Introduction
Accessing C/AL
Start the Object Designer
To start the Object Designer, select the Tools option from the Menu Bar and then
select Object Designer from the list that drops down.
Codeunit
Option Button
Page 148
Chapter 3: Introduction to C/AL Programming
Select an Object
Using the picture above as a guide, scroll through the codeunits to find codeunit
number 358, "DateFilter-Calc", then click on it. Or, if you prefer, use the up and
down arrows on your keyboard to move to codeunit 358.
Look at the C/AL Code
Using the below picture as a guide, press Design once codeunit 358 −
"DateFilter-Calc" has been selected. The C/AL Editor window appeared, looking
something like this:
Each shaded bar is called a "trigger." The C/AL code that you may see listed
below the shaded bar is the "trigger code" for that trigger. If there is no C/AL
code between one trigger and the next trigger, then that trigger is said to be
empty. For example, there is no trigger code between the "OnRun" trigger and
the "CreateFiscalYearFilter" trigger, therefore the "OnRun" trigger is empty.
There are three kinds of triggers. The first is the "Documentation Trigger". This
is not really a trigger and no code in this trigger is run. Instead, you can use the
Documentation trigger to write any sort of documentation you want for this
object. Many people use this space to document their modifications to standard
objects. Every object has a Documentation trigger.
The second kind of trigger is an "Event Trigger". The name of these triggers
always starts with "On." The C/AL code in an event trigger is executed when the
named event occurs. For example, the code in the "OnRun" event trigger is
executed whenever this codeunit object is run. In this case, since there is no
trigger code, nothing would happen. Each object has its own set of predefined
event triggers that can be programmed.
Page 149
Microsoft Navision Development I − C/SIDE Introduction
The third kind of trigger shown here is a "Function Trigger". These triggers are
created whenever you create a "function" in an object. The C/AL code in this
function trigger is executed whenever the function is "called." You learn more
about creating and calling functions in another section. You learn more about
event triggers in your Solution Developer II class.
Closing an Object
After looking at the "CreateFiscalYearFilter" codeunit, close the C/AL Editor
window by clicking the Close Box or by pressing the ESC key. If you have not
changed anything, the object is closed and you can continue. If you have changed
something, the following box pops up:
For now, press the No button (or press the ALT +N key) to discard any changes
you may have made in order to exit the C/AL Editor and close the object.
Look at C/AL Code in a Table Object
Press the Table button in the Object Designer window. Scroll through the Object
Designer window and select Table 18 (the Item table). Press the Design button to
open the Table Designer window. Note that this is not the C/AL Editor. Instead,
it is a list of the fields that make up the table definition. You learn more about
these later.
To get to the C/AL Code, you must open the C/AL Editor. To do this, review the
Tool Bar:
Press the C/AL button. As an alternative, you can press the F9 key. Once you are
in the C/AL Editor, note that there are numerous triggers in this Table Object.
Most of them are empty, but several of them contain C/AL code.
Most of these are in triggers labeled with a field name followed by "OnValidate."
These are event triggers and the code is triggered by the "event" of the user
completing the entry of that field. You learn more about this and the other
triggers discussed here in your Solution Developer class. For now, just take a
look around and then close the C/AL Editor window. Once it is closed, close the
Table Designer, again without saving any changes you may have accidentally
made.
Page 150
Chapter 3: Introduction to C/AL Programming
6. What is the key you press to view or modify code in an object (other
than a codeunit object)?
Practical
Use the Object Designer to look at the code in Form Object 39.
Use the Object Designer to look at the code in Report Object 324. Note that the
code is different depending upon which line (also called a "DataItem") is selected
in the Report Designer. See what happens when you select the line following the
last line in the Report Designer before starting the code window.
Page 151
Microsoft Navision Development I − C/SIDE Introduction
1.
2.
3.
Page 152