Navision Attain Objects
Navision Attain Objects
This material is for informational purposes only. Navision a/s disclaims all
warranties and conditions with regard to use of the material for other
purposes. Navision a/s shall not, at any time, be liable for any special,
direct, indirect or consequential damages, whether in an action of contract,
negligence or other action arising out of or in connection with the use or
performance of the material. This material is subject to change without
notice.
The software described is supplied under license and must be used and
copied in accordance with the enclosed license terms and conditions.
COPYRIGHT NOTICE
TRADEMARKS
The trademarks of Navision a/s and Navision Development a/s are listed on
this Web site: http://trademarks.navision.com
DocID: AT-310-SST-005-v01.00-W1W1
TABLE OF CONTENTS
CHAPTER 1.
INTRODUCTION 1-1
CHAPTER 2.
CHAPTER 3.
CHAPTER 4.
CHAPTER 5.
BASIC DATAPORTS 5-1
CHAPTER 6.
Appendix A.
QUESTIONS I
Appendix B.
ANSWERS XV
PREFACE
When you have completed all four modules in the Navision Attain
Programming course, you can take the Navision Attain Programming test to
be certified as a Navision Attain Consultant in Programming.
The following diagram shows all the courses in the Navision Attain®
training curriculum with subject areas shown in gray:
Chapter 1.
Introduction
C/SIDE Fundamentals
1-2 Navision Attain Objects
This course is designed for anyone who would like to understand the basic
objects found in the Navision Attain Client/Server Integrated Development
Environment (C/SIDE). We suggest this course to anyone who will be using
C/SIDE.
This course will give you a basic understanding of how to create and use
the basic objects found in C/SIDE. You will learn about all the different
object designers and experiment with just a few of the dozens of properties
for each object. The following topics will be presented in this course:
Remember that this course is a self-study. Take as much time as you need
to complete each exercise. Read the material as thoroughly as you can. If
you need to go back and review a section, take time to do that. You must
understand this material in order to be certified.
Introduction 1-3
There are five basic objects in C/SIDE. The first object that you will learn
about in this course is the table object. A table is used to describe how data
will be stored in the database and how it will be retrieved. Understanding
tables is the key to using all of the other objects that you will learn about.
The second type of object that you learn about is the form object. A form is
used to display data to the user in a familiar and useful way. Most forms
allow the user to add records to a table, view and modify records as well.
Then, you will learn about the report object. Reports allow the user to
summarize and print out detail information using the filters and sorting that
he or she chooses. You will learn how to design and then create reports
using the report designer in C/SIDE.
The fourth object that you will learn to use is the dataport object. Dataports
allow you to export or import table data. The dataport and report objects
share an underlying architecture so you will be able to apply what you
learned about reports here.
The last type of object that you need to understand is the codeunit object.
Codeunits allow you, the developer, to organize and group the code that
you write. This is the only object mentioned so far that you might think does
not have anything to do with tables, but it actually does.
This may seem like a huge limitation, but be aware that with every
limitation, there is an increase in freedom. By limiting you to these five
objects, C/SIDE can be streamlined to work faster and more efficiently. It
also frees you up in your design work. You know exactly what you have to
work with. The greatest benefit from this limitation is stability. It is actually
somewhat difficult to create a severe bug in C/SIDE and this is good for
everyone.
1-4 Navision Attain Objects
This section introduces you to the user interface in C/SIDE. If you have not
already installed C/SIDE, refer to the installation manual. If you have
already installed C/SIDE, the installation program has created a new group
that contains all the icons you need to work with in C/SIDE. When the
Integrated Development Environment (IDE) is running, your screen will look
like this:
Title Bar
Menu Bar
Tool Bar
(A)
Work
Area
Status Bar
The user interface gives you access to a number of tools and functions.
Introduction 1-5
Some parts of the user interface, also provide information about the current
state of the system. The table below explains when to use the most
important parts of the C/SIDE user interface.
get information about the name and path of the current title bar
database
see basic status information about your system (such as status bar
the current date and your user ID)
(A) Depending on the task you are working on, the system automatically changes
the icons.
(B) This is also where the user interacts with your applications.
Tables are the fundamental objects that store the actual data; you need
other application objects to insert, modify, delete or show data from tables.
You will typically use a form to enter or retrieve data from the database and
use a report to print data.
Note
The main tool used for developing applications in C/SIDE is the Object
1-6 Navision Attain Objects
Designer (select Tools, Object Designer). This is the tool you use to view
and design tables, forms, reports, dataports and codeunits. In the Object
Designer you choose the type of application object you want to work on.
From the Object Designer you can run an application object or start an
application object designer to modify the design of an existing application
object or create a new application object. The following picture shows how
to use the Object Designer in more detail.
This is where you
access the
designers for
different objects.
You simply choose
the type of object
you want to work
on here.
As you can see, there is a specific designer for each type of application
object. When you create or modify an application, you can work on any
number of application objects at the same time, and each application object
is shown in its own designer. For example, if you work on three new forms
at the same time, then each form will be displayed in its own form designer.
The only designer that you cannot create more than one copy of is the
Object Designer. You will learn more about how to use each of these
designers as you read the following parts of this book.
Introduction 1-7
You have already learned that there are five different types of application
objects in C/SIDE. All five types are based on some general concepts.
Some of these concepts are restricted to one type of application object
while others apply to several types. When you understand these
fundamental concepts, you have a good foundation for creating your own
applications. The table below summarizes how the application objects are
related to these general concepts and explains what each type of
application object is used for.
C/AL: C/AL is the language used for writing functions in C/SIDE. In the
table above, "C/AL" refers to functions written in this language.
Keys: A key defines the order in which data are stored in your tables. You
can speed up searches in your tables by defining several keys that sort
your information in different ways.
Data Items: A data item is a building block you use for defining a model of
your data when you create a report. By using a hierarchy of data items, you
define which data your report should include. A data item represents a
table and when you run a report, the system cycles through the records in
the associated table. A data item can have one or more sections.
The previous section described the general concepts underlying all five
types of application objects in C/SIDE. This section presents another view
of C/SIDE applications. In this view, we are concerned only with how the
information in your application is structured.
As a typical database user, you are not concerned with where each piece
of data is stored on the hard disk or what its size is; you just want to be
sure that when you refer to a name, for example, the correct value is
returned. This is why the C/SIDE database system provides you with a
conceptual representation of data that does not include too many details of
how the data is stored. An abstract data model is used for this conceptual
representation. This data model uses logical concepts (such as objects,
their properties and their relations) that are easier to understand.
This leads us to distinguish between the logical and the physical database.
When we speak about the logical database, we are concerned only with the
structure of the data and the relationships between different bits of
information. That is, we do not deal with how these structures and relations
are implemented. When we speak about the physical database, we deal
only with how the structures in the logical database and the search paths
between them are implemented.
In this course, the term database should be interpreted to mean the logical
database unless otherwise noted.
Basic Tables
What Is a Table?
Creating Tables
Chapter Test
2-2 Navision Attain Objects
The records in the C/SIDE database are stored in tables. A C/SIDE table
may be visualized as a two-dimensional matrix consisting of columns and
rows. The figure below shows a table with nine rows and eight columns.
Each row is a record, and each column is a field.
Columns: Fields
Rows: Records
A table consists of two parts – the table data and a table description. The
table data is the part users often think of as comprising the database
because it contains the actual records with their data fields. The layout and
properties of those fields however, are specified by the table description.
The table description is not directly visible to the user. The following figure
illustrates how the table data and the table description together form a
table:
Table
This is the
- Properties
table
- Triggers description
- Keys
Table Data
Table Description
Table Properties
Triggers
Fields
Properties
Triggers
Keys
Properties
The table description contains some properties that are related to the table
while others are related to the fields in the table. Still other properties are
related to the keys in the table. You can also see from the figure that
triggers are defined both for the table and for the fields in the table. The
following sections will describe these terms in further detail.
2-4 Navision Attain Objects
This section describes how you can use properties in your table design. It
discusses how to modify and use table and field properties.
2 In the Object Designer window, click Table to get a list of the tables.
3 Select a table and click Design. C/SIDE will display the table in the
Table Designer.
4 Place the cursor on an empty line in the Table Designer or click Edit,
Select Object. (If you place the cursor on a line defining one of the
fields in the table, you will get the properties for the field instead of
those for the table.)
6 If you want to modify the setting of a property, simply enter the new
value in the Properties window. When you have entered the new
value, update the property by either pressing ENTER or simply moving
the cursor away from the field.
Example
Just like tables, all fields in C/SIDE have a number of properties that
describe their behavior. When you create a field, C/SIDE automatically
suggests a number of default values for these properties. Depending on the
purpose of the field, you will sometimes want to change these default
values.
2 In the Object Designer window, click Table to get a list of the tables.
3 Select a table and click Design. C/SIDE will display the table in the
Table Designer.
4 Place the cursor on the line in the Table Designer that defines the field
for which you want to access the properties.
6 If you want to modify the setting of a property, simply enter the new
value in the Properties window. When you have entered the new
value, update the property by either pressing ENTER or simply moving
the cursor away from the field.
Example
Use the steps above to look at the NotBlank property of the No. field in the
Customer table (18). This property keeps the user from leaving the No.
field blank. It is used on most primary key fields (you will learn about these
later).
2-6 Navision Attain Objects
In this exercise, you will be asked questions about tables that already exist
in the base application. Answer each question as completely as you can.
What is the option string for the Reserve field in the Customer table?
What type of field is the Date Filter field in the G/L Account table?
What is the value of the TableRelation property of the Currency Code field
in the Customer table?
Basic Tables 2-7
Creating a Table
When you first create a table, it will not contain any data. When you create
the table you have to decide which types of information you want to store in
it.
In the Table Designer, for each field you add to the table, you enter the field
number, name, data type and, optionally, a length and a description. The
following subsections describe how to do this.
After you have added fields to a table in the Table Designer, you must save
the table before you can add any records. Once you have saved a table, it
will appear in the list of tables in the Object Designer.
All the tables and fields you create have two forms of identification:
When you have selected an identification number and name for a field, you
have to select an appropriate data type. You can use 11 different types of
fields in the C/SIDE database system. Each type is designed to hold a
specific kind of information, such as text, numbers, dates and so on.
normal date.
(A) The calculation of the size of a specific SQL Server record requires
more than simply summing the sizes of the field values. Refer to Microsoft’s
SQL Server documentation for further information.
Basic Tables 2-11
(B) This is the SQL server data type that Navision Attain uses when it
creates the Navision Attain data type. For further information, see the
manual Application Designer’s Guide.
Note
4 Enter the Field Numbers, Field Names, Data Types and Lengths (if
applicable) for each field:
1 Model Code 20
5 Description Text50
6 Save the new table by closing the Designer window, click Yes at the
Save dialog, and then enter the Table ID Number (91200) and Table
Name (Vehicle) in the Save As dialog.
In this exercise, you will add data to the table created in the previous
exercise.
You are now viewing the data in the new Vehicle table. Notice that it is
currently empty. The form you have open was auto-created by the Client
application when you chose to run the table. This is a basic tabular form.
Now, you can enter some test data for your table and begin testing the
functionality.
7 Close the form and let’s fix the problem you have discovered. This is
done in the next exercise.
2-14 Navision Attain Objects
The database keeps track of each record by means of the record's primary
key. You can consider the primary key of a record as the name of the
record. The name of each record in a particular table for a particular
company must be unique. This name is how the DBMS retrieves and
updates records.
The primary key is always active; the DBMS keeps the table sorted in
primary key order and rejects records with duplicate values in primary key
fields. Therefore, the values in the primary key must always be unique. Be
aware that it is not the value in each field in the primary key that must be
unique, but rather the combination of values in all the fields comprising the
primary key.
The C/SIDE database system does not support tables without keys.
3 Click the Design button. This opens the Table Designer window for the
Vehicle table.
Basic Tables 2-15
4 On the main menu, click View, Keys. This displays the Key Designer
window. Notice that the primary key contains only one field - Model.
This means that you cannot enter two records with the same Model.
For your example this is not a good choice for the primary key. If you
were to include Serial No. in the primary key, then you could enter the
same model many times as long as the Serial No. field is different for
each.
5 Click in the Key column on the first line in the Key Designer window.
6 Click the Assist-Edit button. Here you can select more fields to be part
of this key.
7 Add the Serial No. field to this list and click OK.
8 Exit the Table Designer window and save and compile the table. The
primary key has been changed.
9 Finish entering the data from step 1. Notice that the records are sorted
in the order of the primary key fields (Model and then Serial No.).
2-16 Navision Attain Objects
Secondary Keys
Note
The number of fields in the primary key together with all the fields in each
secondary key must not exceed 20.
This means that if your primary key includes four distinct fields, then a
secondary key can include these four fields and at most 16 others.
Correspondingly, if your primary key consists of 20 distinct fields, then your
secondary keys must consist only of combinations of these fields.
When you define a secondary key and mark it as active, the system will
automatically maintain an index reflecting the sorting order defined by the
key. Several secondary keys may be active at the same time.
A secondary key can be changed into an inactive key. This means that the
DBMS does not use time during updates to maintain its index. Furthermore,
an inactive key doesn’t occupy database space.
Inactive keys can be reactivated; this process may consume some time
depending on the size of the table because the DBMS has to scan the
entire table to rebuild the index.
The fields comprising the secondary keys are not guaranteed to contain
unique data; the DBMS does not reject records with duplicate data in
secondary key fields. If two or more records contain identical information in
the secondary key, the DBMS will use the primary key for the table to solve
this conflict.
Basic Tables 2-17
For some of your users, the date of manufacture and transmission is more
important. Those users would like to be able to change the order of the
records on the form to Date of Mfg., Transmission. To accomplish this you
need to set up a secondary key.
3 Click the Design button. This opens the Table Designer window for
the Vehicle table.
4 On the main menu, click View, Keys. This displays the Key Designer
window.
6 Click the Assist-Edit button. Here you can select the fields to be part of
this key.
7 Select the Date of Mfg. field first and then the Transmission field.
The order of the fields is important. In the order described, the records
will be sorted by Date of Mfg. first and then by Transmission (if some
of the dates are the same).
8 Exit the Table Designer window and save and compile the table. The
secondary key has been created.
2-18 Navision Attain Objects
In this exercise, you will use the secondary key created in exercise 5.2.4.
5 You are now viewing the data in the new Vehicle table. Notice that the
data that you previously entered is still there. You may also notice that
the records are still sorted in primary key order.
1 Click the Sort button on the Tool Bar. This displays the Sort window.
2 Choose the new key you created (the second key in the list) and click
OK. The records should immediately resort themselves using the new
key.
Look at the records that have a Date of Mfg. of 01/15/00. What order are
these records in since they have the same date?
Look at the records that have the same Date of Mfg. and the same
Transmission. What order are these records in?
If your database contains tables with related data you can define a
relationship between them. You relate tables by specifying one or more
fields that contain the same value in related records. These matching fields
often have the same name in each table. You can use relationships to:
Table relations are defined using the TableRelation property. This property
is very flexible and allows you to define both simple and advanced table
relations. A typical simple table relation consists of just a table ID and an
optional field ID, while advanced table relations are typically prefixed with a
conditional statement and include filters.
When you create a table relation, you are specifying which field to lookup in
another table. If the optional field ID is left blank, it is the first field in the
primary key that the relation is made to. To make a relation to the second
or third field in a primary key, you must specify the field ID.
Note
If the field specified is not the first field in the primary key, the other fields
that are before it in the key must be filtered to one value. This is not a true
requirement of the system, but only makes sense in a real application. The
user must not be confused when presented with choices.
Basic Tables 2-21
Create a table with the following fields. The table will hold information about
the sale of an item. Do not be concerned here with why you would need
this table. It is not of any particular use, except in this exercise.
9 Amount Decimal
Save the table with the name Sales Transaction and the ID 91300.
Now that the basic table has been created, add two simple table relations.
2 Select the Salesperson Code field. This field will hold values from the
Salesperson/Purchaser table. The user may lookup a value from the
table or type in a value, but it must exist in the
Salesperson/Purchaser table. Due to these requirements, you need
a table relation on this field.
4 Select the TableRelation property for the Salesperson Code field and
click the assist-edit button.
Now, you need to test your table relation. The following steps will
demonstrate how powerful table relations are. Keep in mind that the lookup
buttons on a field that has a table relation open the default lookup form for
the related table. Without a form for the table, the lookup button does not
work. In this example, there are already forms defined for the
Salesperson/Purchaser table.
2 In the Line No. field of the first empty line, enter 10000.
4 Select AH (Alice Hart) and click OK. Notice that the Salesperson
Code field now has the value AH. Because the TableRelation was
only set up to the table (not to any particular field), the lookup returns
the value from the first primary key field. Because the
Salesperson/Purchaser table only has one field in the primary key,
there was no need to specify a field (only primary key fields can be
chosen in a TableRelation).
5 Delete the value AH from the Salesperson Code field and type just
an “a”. What happens when you press Enter?
6 Delete the value again and type in XY. What happens when you press
Enter?
Basic Tables 2-23
Changing the primary key values of a record in a table changes the name
of the record. This is called this renaming a record. In this exercise, you will
see the results of renaming a record that has other records related to it via
a table relation.
8 Select the line that you added earlier (the record with your initials and
name) and change the primary key value. Instead of your initials,
change it to the first three letters of your last name.
10 How long did it take to change that value? Did it take longer than you
expected?
11 Run table 91300 (Sales Transaction) and check the data it contains.
Did any of the records here change? Why?
8 You may have noticed that you did not put a table relation on the Item
No. field.
You must now relate the Item No. field to the Item table with a simple table
relation.
Basic Tables 2-25
In this exercise, you add filters to one of the table relations that you created
in the previous exercises.
2 Select the Salesperson Code field. This is the field that you want to
change.
3 Open the Properties window for this field and select the
TableRelation property.
4 Click the assist-edit button to open the Table Relation window. Notice
that only the Table field is filled in. You need to also give the relation a
table filter.
5 Select the Table Filter field and click the assist-edit button to bring up
the Table Filter window. In this window you can specify filters on as
many fields in the related table as you need to. For each field you add
to the list, you can filter it in three ways – by a constant value, using a
filter expression or by a field in the current table (91300). In this case
you will use a filter expression.
6 In the first column, lookup and select the Commission % field. This
stores the commission rate for the salesperson.
7 In the second column, click the dropdown button and select Filter. You
must choose filter because of the values that you want to filter on,
specifically where Commission % is greater than zero. You can only
use relational operators with the filter option. Const and Field options
are exact matches only (equal to).
2-26 Navision Attain Objects
11 With the Properties window open, move your mouse over the Value
field of the TableRelation property. This will display the complete table
relation as text. Make sure that it contains the following (if not redo this
exercise):
12 Close the Properties window and save, compile, and exit the table.
When you use the lookup button on the Salesperson Code field do you
see all the records in the Salesperson/Purchaser table? If not, why not?
Can you enter in the value AH into the Salesperson Code field? If not, why
not?
Basic Tables 2-27
In this exercise, you will add conditions to one of the table relations that you
created in the previous exercises.
You may know that in Navision Attain you can sell several different types of
things, including items, resources, and G/L accounts. In your table, you are
only tracking items. It would be more accurate to have resource numbers
and G/L account numbers as part of your table as well. You could add two
more fields to hold those values but it would be more efficient to use the
one field you already have and let it hold any one of the three types. To
accomplish this, you will need to add a type field to your table so that the
user will know whether the number is an item number, resource number or
G/L account number.
2 Add the following field to the table. Notice that the field number used is
before the Item No. field. This is not critical, but because the Item No.
field will now depend on the Type field, it is normal for the Type field
to be filled in first.
3 To enter the options, open the Properties window and enter the
options in the OptionString field. Enter the properties very carefully.
They must be separated by commas and contain no spaces.
4 Now, change the name of the Item No. field to just No. This will be
more accurate because it may not be an item that was sold.
5 At this point, it will be easier if you save, compile and exit the table.
Whenever you add a new field to an existing table, the table definition
is not updated until you save the table. This step makes the following
steps a bit simpler because the new field will now show up in the list of
fields.
6 Reopen table 91300 in the table Designer and select the No. field.
The table relation for this field needs to be changed. You will give it
the ability to lookup into any of the three tables: G/L Account, Item or
Resource.
7 Open the Properties window for the No. field and click the
TableRelation property.
2-28 Navision Attain Objects
9 First enter the names of the three tables in the Table column. Put
each table on a new line (you may want to delete the previous line that
was related to the Item table before you begin). However, you cannot
save the TableRelation like this. You still need to set the conditions.
Anytime you have more than one line in the TableRelation dialog you
must have conditions set as well.
Type=CONST(Item) Item
Type=CONST(Resource) Resource
11 In the Table Relation window, select the first line in the Condition
column.
12 Click the AssistButton k to open the Table Filter window. This is the
same window that we used to set the Table Filters for the table
relation. However, for a condition we are limited to CONST or FILTER
choices (FIELD is not available). See appendix B for more information.
14 In the Type column, select the value CONST (this should already be
the default).
Basic Tables 2-29
15 In the Value column, enter Account. You can also enter the number 0.
and when you press Enter or Tab, the zero will change into the word
Account.
17 Repeat steps 10-15 for the other two lines in the Table Relation
window.
When you use the lookup button on the No. field, what form is displayed?
What if you change the Type field?
Try changing Type to Item and looking up an item number. Now, change
Type to Resource. What happens? Is the value for No. valid?
Now try retyping the value in the No. field after changing the Type as
described in the previous question. What error do you get?
2-30 Navision Attain Objects
In addition to the conventional data fields that simply hold values, three
kinds of specialized fields are available for data retrieval:
• SumIndexFields
• FlowFields
• FlowFilter Fields
This is the fundamental feature of the Navision Attain database that forms
the basis for FlowFields. SumIndexFields permit fast calculation of sums of
numeric columns in tables, even in tables with thousands of records. This
occurs because SumIndexFields are maintained when the database record
is updated.
For example, if you want the sum of all the values in the Amount field. In a
conventional database system, the DBMS is forced to access every record
and add each value in the field Amount, a very time-consuming operation
in a database with thousands of records. With Navision Attain, it can be as
little as two accesses (if the best key is used) to sum the Amount for these
records.
This tells the DBMS to create and maintain a structure that contains the
accumulated sum of values in a column. When a new current key is
selected, any SumIndexFields associated with it becomes accessible.
FlowFields are not a permanent part of the table data. A FlowField can be
thought of as a virtual field, which is an extension to the table data.
Actually, the information in the FlowFields exists only at run time. The
values in FlowFields are automatically initialized to 0 (zero). To update a
FlowField, you must use the C/AL function <Record>.CALCFIELDS. Notice
that when a FlowField is the direct source expression of a control on a form
the FlowField is automatically calculated when the form is displayed.
End-users may want to limit calculations so that they include only those
values in a column that have some specific properties. For example the
user may want to sum up only the amounts of customer entries that are
entered in April. This is possible if the application has been designed using
FlowFilter fields in connection with the FlowFields.
In this exercise, you will calculate sums for the data you enter. This
information will help us confirm the sums that get calculated automatically.
2 Delete all of the current records in the table. This will ensure that the
totals you get are the same as the ones in the answer guide. The
easiest way to delete all the records is to click in the upper left gray
box of the form (this should select all the records) and then press F4
(this should prompt you for confirmation and then delete the records).
3 Now that the table is empty, enter the following records into the table.
Make sure you use the values given.
4 Calculate the sum for the entire table and for every unique
Salesperson Code. Write down the sums in the following table:
For JR
For MF
For PS
For ALL
Note that this would be much easier if you could sort the records by
Salesperson Code first. Of course, the only way to do this is to add a key.
So, DO NOT do this yet.
In this exercise, you will create a FlowField that displays the sum of records
in the Sales Transaction table (91300).
The data type must be decimal because you want to display a sum
(averages require a decimal as well). A sum FlowField calculates a
decimal value.
Method Sum
Table 91300
Field Amount
9 Close, save and compile the table. If you receive a permissions error,
the ID that you gave the field is incorrect (see step 2).
You have now successfully created a FlowField. The next step is to test it.
Basic Tables 2-35
What do we need to change to correct the problem (hint: read the error
message very carefully)?
You can simply let the error message tell you what to do. In a moment, you
will learn the correct procedure.
1 Open the Sales Transaction table that the error message mentions in
the Table Designer.
2 Click View, Keys to open the Keys Designer. This is where you will
create your key and your SumIndexField.
To test your SumIndexField, you need to view your FlowField. Run table 13
(Salesperson/Purchaser).
Fill in the following table with the values displayed the new FlowField,
Sales.
For JR
For MF
For PS
Do they match any of the values from exercise 5.4.1 (your manual sums)?
Which ones do they match?
In this exercise, you will correct the FlowField that you started above. The
problem with the FlowField was that you left out a part of the CalcFormula.
For most FlowFields, you must use a Table Filter. Table filters allow the
user to Sum some of the records in the table instead of all the records.
In the FlowField that you created above, you only want to sum records in
the Sales Transaction table that have a particular Salesperson Code. For
example, if the Code field in the Salesperson/Purchaser table is ‘PS’, then
we only want to sum records in the Sales Transaction table that have a
Salesperson Code of ‘PS’.
5 Notice that you left the Table Filter field blank in the previous
exercise. This is the part of the CalcFormula that you need to
complete. When you leave this empty, the calculation in your
FlowField is based on all the records in the table.
6 Click the assist-edit button to open the Table Filter window. Set a
filter like the following:
The Field column corresponds to fields in the Sales Transaction table (the
table you are summing). Because you have the Type column set to Field,
the Value column represents fields in the table you are currently designing
(Salesperson/Purchaser).
2-38 Navision Attain Objects
What do we need to change to correct the problem (hint: read the error
message very carefully)?
In this exercise, you will learn the proper procedure for deciding how to
create your SumIndexFields.
5 Write the name of the table that is named in the window in the
following space.
6 Write the name of the field that is named in the window in the following
space.
7 Click the assist-edit button in the Table Filter field to open the Table
Filter dialog. Write down all of the fields that are mentioned in the Field
column (the first column). (You may not use all of these spaces.)
These fields are the fields in the table you are summing that you need
to sort by. You need a key with all of these fields in it. The order of the
fields in the key is not important for this FlowField, although, you may
want to use this key for other things as well.
8 Now, you know the table, the field and the key. Close this table and
design the table you identified in step 5.
9 Click View, Keys to open the Keys Designer. This is where you will
create your key and your SumIndexField.
x Salesperson Amount
Code
If this does match what you wrote down in steps 5-7, start over with
step 1.
To test your SumIndexField, you need to view your FlowField. Run table 13
(Salesperson/Purchaser).
You will create a FlowFilter that allows the user, you, to change the sum
based on the Type field in the Sales Transaction table. This will allow the
user to use your FlowField for four different sums – total for accounts sold,
total for items sold, total for resources sold, or the total of all sales.
5 Close, save, and compile the table. This step makes the next few
steps easier.
10 In the Table Filter field, click the assist-edit button to open the Table
Filter window. This is where you need to change the FlowField so that
it will use the FlowFilter.
11 Click on an empty line (this should be the second line in the dialog).
Enter the following in the empty line:
You may not notice any difference, but that is good. It means that nothing
broke. In the next exercise, you will test the FlowFilter itself.
In this exercise, you will learn how to use the FlowFilter as the user would.
You will also learn that changes you make to a FlowField can have
unexpected results.
3 You may notice that the Type Filter field does not appear on our form.
This is because FlowFilters have a special form. Click the FlowFilter
button on the toolbar or click View, FlowFilter to display this special
form. This is the FlowFilter window. This is where you can change the
value of a FlowFilter.
4 In the Filter column for the Type Filter field, select the type Item.
Nothing has happened yet. You still need to click OK or Apply.
5 Click OK.
What happened?
Why did you only get the message after you set the FlowFilter?
What is the next step that you should take to correct the problem?
3 Add the Type field to the secondary key that you created earlier so
that the key looks as follows:
x Salesperson Amount
Code,Type
2-44 Navision Attain Objects
You could create a whole new key, but that is not necessary. This one key
will work for the FlowField whether you are using the FlowFilter or not.
To test your fix, repeat steps 3-5 from the previous exercise.
In this section, you will investigate some very useful properties and why
you would use them.
In this exercise, you will discover the need for the NotBlank property. You
will begin by simply entering some records.
3 Without entering a value in the Model or Serial No. fields, click the
Description field.
5 Click on another record in the table (it does not matter which one).
Notice that your ‘New Vehicle’ record is inserted into the table.
What is the “name” of the record (remember that the name is the value
of the primary key fields)?
How could we eliminate blank records being put into the table by
accident?
Note
If you try to use the NotBlank property on fields that are not in the Primary
key, it will not behave the same way. Repeat the process above for the
Description field and see if NotBlank works the same way on it.
In this exercise, you will discover the need for the Editable property. You
will begin by modifying some records.
2 Click on the Sales column. Notice that this field is editable (can be
changed). Remember that this is the FlowField that you created.
FlowFields are calculated values.
What happened?
Did the change last (if you close the table and run it again, is the value still
500 for PS)?
Run table 91300 (Sales Transaction) and manually calculate the sum of
the values for PS (you may want to change the sort first).
What is the new sum? What was the old sum (section 2.7.1)? What is the
difference?
Basic Tables 2-47
Can you identify the line that may have changed the sum?
This is not a good situation. Users looking at this FlowField must not be
allowed to accidentally change the sum. In fact, for other types of
FlowFields, (average, exist and so on) the user would receive an
immediate error, if they tried to change them. So, it is a good practice to
make most FlowFields non-editable.
2 Click on the field that you want to change (the Sales field).
7 Test your change by running the table and trying to edit the field.
Note
In some situations, the behavior that you observed is exactly what you want
to happen. This functionality is used in the G/L Budgets, for example, to
make it easier for the user to enter budget information. You may want to
look at the budgets to see how this is done.
2 Enter a new record with the following values (notice that the amount
has three decimal places).
By default the DecimalPlaces property is set to 2:2. The number before the
colon is the minimum number of decimals that will be displayed to the user.
The number after the colon is the maximum number of decimals that the
user can enter.
In your case, you cannot enter three decimal places because there is a two
after the colon. To change this, follow these steps:
What happened?
What is displayed in the field if you enter the Amount 234.1 and press
Enter?
Basic Tables 2-49
What is displayed in the field if you enter the Amount 234 and press Enter?
What is displayed in the field if you enter the Amount 234.110 and press
Enter?
All objects and fields have a CaptionML property. This property allows the
user to switch languages and have the captions shown in the language
they select. Additional languages can be added and for each language the
CaptionML property value is set to the language’s correct term. The English
(United States) (ENU) language is mandatory. When creating a new table,
go the Table properties to populate the CaptionML for the table name. See
the example for the Name field CaptionML below:
For Option Data Types the OptionCaptionML property must be filled out as
well.
2-50 Navision Attain Objects
The following picture shows the Properties window for the Document
Type field:
Basic Tables 2-51
Understanding the standard types of tables in Navision Attain will help you
to quickly understand how different areas of the application are designed.
A Master table contains information about the primary focus subject of its
functional area. For example, the Customer table, which is the primary
focus of the Sales & Receivables functional area, is a Master table.
Generally, many other tables are related to a Master table and the Master
table itself is related to many other (usually Supplemental) tables.
Most functional areas have only one Master table, though occasionally,
there will be two Master tables for a functional area.
The name of this table is the name of one of the records in the table.
For example, the Customer table is so named because each record within
it contains information about one customer.
The Primary Key of a Master table is a Code field of length 20, named
"No." or occasionally "Code".
The description field of this table is a Text field of length 30, named "Name"
or "Description".
These two fields are included in the DataCaptionFields property of the table
so that these will display in the title bar of this table's forms.
Basic Tables 2-53
Associated Forms
There are three or more forms that are used with a Master table.
• Card Form
• List Form
• Statistics Form
First is a Card Form that is used to edit the records in the Master table.
The name of this form will be the name of the table followed by the word
"Card". Thus the Card form for the Customer table will be named
Customer Card.
It will have at least one additional menu button (besides the usual OK,
Cancel and Help) and this has the same name as the table. The menu
button will provide links to other forms giving related or subsidiary
information. One of these choices will be a link to the List form that can be
triggered by pressing F5 on the keyboard. Another of these choices will be
a link to the form showing the related Ledger table that can be triggered by
pressing Ctrl+F5 on the keyboard. Another of these choices will be a link to
the related Statistics form that can be triggered by pressing F9 on the
keyboard.
The second form used with a Master table is a List Form, which is used to
view the records in the master table. Unlike the card form, this form cannot
be used to edit the master table.
The name of this form will be the name of the table followed by the word
"List". Thus the List form for the Customer table will be named Customer
List.
It will have at least one additional menu button (besides the usual OK,
Cancel and Help) with the same name as the table. It will provide links to
other forms giving related or subsidiary information. One of these choices
will be a link to the Card form that can be triggered by pressing Shift+F5 on
the keyboard. Another of these choices will be a link to the form showing
the related Ledger table that can be triggered by pressing Ctrl+F5 on the
keyboard. Another of these choices will be a link to the related Statistics
2-54 Navision Attain Objects
The third form used with a Master table is a Statistics Form, which is used
to view calculated information about the record in the Master table. This
information is put on a separate form from the Card form for performance
reasons since this information is calculated.
The name of this form will be the name of the table followed by the word
"Statistics". Thus the Statistics form for the Customer table will be named
Customer Statistics.
The name of this table is the name of one of the records within the table.
For example, the Currency table is named "Currency" because each record
within it contains information about one currency.
The description field of this table is a Text field of length 30 or 50, named
"Description". Some Supplemental tables do not contain a description field
and some contain a description field whose name is "Name".
Basic Tables 2-55
Associated Forms
This form generally has no buttons except for the standard OK, Cancel and
Help. This form is set as the LookupFormID property of the table since it is
used not only for edit but also for Lookups into this table.
For example, the Item Vendor table is a table that contains subsidiary
information (vendor numbers) for the Item table in the Inventory functional
area.
The Primary Key for the Subsidiary table will contain a field for each table
to which it is subsidiary, each of which is related to that table.
For example, the Primary Key fields for the Item Vendor table include an
Item No. field (related to the Master table Item) and a Vendor No. field
(related to the Master table Vendor).
The Primary Key can also contain an Integer as the last field (named Line
No.) to differentiate multiple records with the exact same subsidiary
relationship. For example, the Employee Qualification table has an
Integer field in the Primary Key to differentiate two records for the same
Employee.
Subsidiary tables are generally not related to other tables except for the
Primary Key fields mentioned before. Other tables are generally not related
to a Subsidiary table due to the fact that each Subsidiary table has multiple
fields in the Primary Key.
The name of this table is generally made up of the names of the table or
2-56 Navision Attain Objects
For example, the table that is subsidiary to both the Vendor table and the
Item table is named Item Vendor. Whatever it is, it is a singular name that
describes one record contained within the table.
Associated Forms
A Subsidiary table uses one form for editing and viewing purposes and this
form is usually called from a button on the Master or Supplemental form to
which it is subsidiary.
The name of this form is usually the plural of the name of the table.
If the Primary Key for the Subsidiary table contains an Integer, the form will
be a Worksheet form and it will not contain any of the Primary Key fields.
Instead, the Primary Key fields other than the Integer will be filtered so that
they are viewed and set automatically.
If the Primary Key for the Subsidiary table does not contain an Integer, the
form will be a Tabular form and it will not contain the Primary Key field of
the master table. Instead, this field will be filtered so that it is viewed and
set automatically.
In both cases, the form is linked back to the form that called it up so that if
the record there is changed, the filters on this form are also changed. This
ensures that the correct related records are always in view.
This table is very much like a Subsidiary table, in that, it is related to the
corresponding Master table, but it has different characteristics, as we will
see. It is also related to many other tables, mostly Supplemental tables.
Register tables are related to Ledger tables but rarely will another table be
related to a Ledger table.
The name of the Ledger Table is usually the name of the Master table to
which it is related, plus the words "Ledger Entry" describing one of the
records in it (an entry). Since this is sometimes lengthy, the name is
sometimes abbreviated.
For example, the Customer Ledger Entry table is actually named Cust.
Ledger Entry.
Sometimes, when there is more than one Master table, the name is the
functional area followed by the words "Ledger Entry". Thus, the Ledger
table for the Payroll functional area is named Payroll Ledger Entry.
The Primary Key of a Ledger table is an Integer named "Entry No.". This
Primary Key is always generated automatically by the posting routine that
controls this Ledger table.
There is always a field in the Ledger table that has a table relation to the
Master table associated with this ledger table.
Associated Forms
A Ledger table uses a List Form to display information to the user. This
form is named with the plural of the Ledger table. For example, the name of
the form that displays records from the Customer Ledger Entry table is
Customer Ledger Entries.
2-58 Navision Attain Objects
This form can be displayed from the Master table forms by pressing the
Ctrl+F5 keys on the keyboard.
There is one record per posting process and the Register table
corresponds more closely to the posting routine rather than the functional
area.
For example, the table that contains the list of entries made to the
Customer Ledger Entry table is the G/L Register table. This is because
the Customer Ledger Entries are posted from the General Journal table
using the General Journal posting procedures. The Register Table is
related to its corresponding Ledger table or Tables.
The Primary Key of a Register table is an Integer field named "No.". The
Primary Key is always generated automatically by the posting routine that
controls this Register.
Other standard fields for the Register table include two fields, both Integer
fields related to the corresponding Ledger table, called "From Entry No."
and "To Entry No."
Associated Forms
A Register table uses a List form to display its information to the user.
Basic Tables 2-59
This form generally has the same name as the Register table.
A Journal Table is the primary transaction entry table for a functional area.
Journal tables are related to many other tables including the Master table,
Supplemental tables, Subsidiary tables and even the corresponding Ledger
table (for application purposes). Other tables are not related to the Journal
table.
Because of their use for transaction entries, Journal tables have more
trigger code than most other table types.
The name of this table is the name of the type of transaction being posted,
followed by the words "Journal Line".
For example, the name of the table in which the user enters transactions to
the Resource functional area is Resource Journal Line. Each record in
the journal table contains one line from the journal.
The names of these two tables are the same as the name of the Journal
table, except followed by Journal Batch or Journal Template rather than
Journal Line. Thus, the two corresponding tables for the Resource Journal
Line are named Resource Journal Template and Resource Journal
Batch.
The Primary Key for the Journal table is made up of three fields, the field
that is related to the Journal Template table, the field that is related to the
2-60 Navision Attain Objects
Associated Forms
The form that is used for a Journal table is a Worksheet Form, which is
used to make entries to this table.
This form is named the same as the table, except without the "Line". Thus
the Worksheet form for the Resource Journal Line table is named
Resource Journal. Sometimes, the form is named for the type of data
being input. For example, one of the (many) Worksheet forms used with the
Gen. Journal Line table is called Sales Journal.
When it is called, it is filtered by the Template and Batch fields, and the
AutoSplitKey property of the Worksheet automatically sets the Line No.
field.
The Worksheet form always includes a menu button that has the same
name as the related Master table. It includes a way to call up the Card form
for the Master table that can be triggered by pressing Shift+F5 on the
keyboard. It also has a way to call up the Ledger for that current Master
record, which can be triggered by pressing Ctrl+F5 on the Keyboard.
The Worksheet form also always includes a menu button that is named
"Posting", which lets the user print the test report, post, or post and print a
register and sometimes includes a choice to reconcile. The Worksheet form
also usually includes other buttons that lets the user perform various
processing functions.
For most users, it is the primary means of entering data as it is the one
most often used. Because they are used for transaction entries, Document
tables have more trigger code than most other table types.
Basic Tables 2-61
The Document Header table holds the main transaction information. For
example, in the case of a sales transaction, the Sales Header table
contains information pertaining to the order or invoice as a whole.
The Document Line table holds the detailed information for the transaction.
For example, in the case of a sales transaction, the Sales Line table
contains information about each individual line of the order or invoice. The
Document Line table is a Subsidiary table to the Document Header table.
Like Journal tables, Document tables are related to numerous other tables,
including Master, Supplemental, and Subsidiary tables, but rarely is
another table related to a Document table.
The name of the Document Header table is the name of the transaction or
document, plus the word "Header". For example, the Document Header
table that contains Sales transactions is named Sales Header. Each record
contains one sale (order or invoice).
The name of the Document Line table is the name of the transaction or
document, plus the word "Line". For example, the Document Line table that
contains Sales transactions is named Sales Line. Each record contains
one line from a sale (order or invoice).
Another example, the Document Line table that contains Finance Charge
Memo transactions is named Finance Charge Memo Line. Each record
contains one line from a Finance Charge Memo.
2-62 Navision Attain Objects
For most Document Header tables, the Primary Key is a Code field of
length 20 containing the document number and named No..
For most Document Line tables, the Primary Key has two fields – a Code
field of length 20 containing the document number and an Integer field
named Line No.. The Code field is table related to the Document Header
table, and so is named according to that table's name (without "Header")
followed by that table's Primary Key field. For example, the Code field in
the Primary Key of the Finance Charge Memo Line table is named Finance
Charge Memo No..
In the case where the Document Header has a document type, the Primary
Key of the Document Line table has 3 fields – an Option field named
Document Type, a Code field of length 20 named Document No., and an
Integer field named Line No.. Again, the Code field is table related to the
Document Header table.
Associated Forms
A Document Header table uses a special kind of Card form to display one
header record at a time for the user to view and edit information.
The name of this form is the name of the document that it displays. This is
true even if the table can contain multiple types of documents since, in this
case, the form is set up to only view information from one type. It contains
tabs to split the fields into logical groups to make it easier for the user to
edit the information.
The form also includes other buttons that let the user perform various
processing functions.
The thing that makes a Document Header form different from a Card form
Basic Tables 2-63
The name of the form is the name of the document followed by either
"Lines" or "Sub-Form". Since this name never shows, it is not that critical.
What is critical is that the size of this form is exactly the same as the size of
the sub-form control in which it is displayed.
None of the Primary Key fields should be included on this form as the form
is filtered (using a link) for all of the Primary Key fields except the Integer
field, which is handled automatically by the AutoSplitKey property of the
Worksheet.
The Document Header table also uses a List form to let the user view
multiple documents at the same time.
The name of this form is, like most List forms, the name of the table
(without the word "Header") followed by the word "List". This List form can
be invoked from the Header form by pressing the F5 key on the keyboard.
Document History tables are to Document tables what Ledger tables are to
Journal tables.
To aid with that copying process, the Document History table generally has
the same fields with the same field numbers, names and properties as the
original Document tables.
Since the Document History tables record posted transactions, they are
generally not editable by the user, although they can be deleted if the user
has that permission.
Other than the above, the Document History tables and forms are the same
as the corresponding Document tables.
Naturally, the sub-form is a List form rather than a Worksheet form since
2-64 Navision Attain Objects
And the names include either the word "Posted" or "Issued" to indicate that
it is a history table rather than a transaction entry table.
A Setup Table is a table that is designed to hold only one record. This
record contains various fields that are used to select options for Navision
Attain or to hold data that is applicable to the company as a whole.
The name of this table is usually the name of the functional area it is meant
to set up, followed by the word, "Setup". For example, the table that
contains the setup information for the General Ledger functional area is
named General Ledger Setup. One exception to this rule is the Company
Information table.
The Primary Key for this table is a Code field of length 10, named Primary
Key. It is always left blank as only one record per table is allowed. There is
no description field for this table type.
There is only one form set up for this table, and it is a Setup Form as
described in the next section. The form has the same name as the table.
The primary key field is not included on this form.
Note
There are some tables containing the word "Setup" in their name, which
have more than one record. These tables generally follow the rules of the
Subsidiary Tables described previously, not the rules outlined here.
Basic Tables 2-65
This concludes the table exercise section. If you did not understand what
you did in this chapter, be sure to reread the sections about tables and then
redo these exercises.
It is critical that you grasp the concepts you learned in this chapter. Tables
are the foundation on which everything else is built in Navision Attain.
Here are the answers to all the questions in the previous sections:
What is the option string for the Reserve field in the Customer table?
Never,Optional,Always
The Balance At Date field has one more filter line in the Table Filter that
includes the Date Filter.
What type of field is the Date Filter field in the G/L Account table?
Date, FlowFilter
What is the value of the TableRelation property of the Currency Code field
in the Customer table?
Currency
No questions here
You cannot enter the second record. You get the error: The record already
exists.
2-66 Navision Attain Objects
The Primary key is only the Model field. It is the first field in the table and
that means that the Model field must be unique for every record.
No questions here
No questions here
Look at the records that have a Date of Mfg. of 01/15/00. What order are
these records in since they have the same date?
They are in order by Transmission, the second field in the secondary key.
Look at the records that have the same Date of Mfg. and the same
Transmission. What order are these records in?
If any Primary Key field is not used in the secondary key, it is added to the
end of the secondary key.
Enter ‘a’ in the Salesperson Code field. What happens when press Enter?
The client finds the first value in the table that has an A as the first letter
and chooses that record for you.
Type ‘XY’ into the Salesperson Code field. What happens when press
Enter?
How long did it take to change that value? Was it longer than you
expected?
Yes.
Check the data in table 91300 (Sales Transaction) by running it. Did any
of the records here change? Why?
Yes. All the records that had my initials in them changed to XXX.
Because the renaming of a record also changes any values that are related
to it in other tables.
When you use the lookup button on the Salesperson Code field do you
see all the records in the Salesperson/Purchaser table? If not, why?
No. The table filter on the table relation filtered out any records with a
Commission % <= 0.
Can you type in the value AH into the Salesperson Code field? If not,
why?
When you use the lookup button on the No. field what form is displayed?
What if you change the Type field?
The table relation now depends on the Type field. Using the lookup button
when Type=Item displays the Item List form and so on.
Try changing Type to Item and looking up an item number. Now, change
Type to Resource. What happens? Is the value for No. valid?
Nothing happens!
No. The value in No. is an Item No. not a Resource No. It is invalid.
2-68 Navision Attain Objects
Now try retyping the value in the No. field after changing the Type as
described in the previous question. What error do you get?
For JR 1050.00
For MF 800.00
For PS 185.00
No questions here
I received an error.
What do we need to change to correct the problem (hint: read the error
message very carefully)?
I need to add a key to the Sales Transaction table that has the correct
fields and a SumIndexField of Amount.
No.
For JR 2035.00
For MF 2035.00
For PS 2035.00
No.
Do they match any of the values from exercise 5.4.1 (your manual sums)?
Which ones do they match?
Yes.
It is not summing the records for each Salesperson. It is summing all of the
Salespeople together.
I received an error.
What do we need to change to correct the problem (hint: read the error
message very carefully)?
I need to add a key to the Sales Transaction table that has the correct
fields and a SumIndexField of Amount.
No.
No questions here
What happened?
An error occurred.
Why did we only get the message after we set the FlowFilter?
What is the next step that you should take to correct the problem?
What is the “name” of the record (remember that a name is the values of
the primary key fields)?
How could we eliminate blank records being put into the table by accident?
What happened?
Did the change last (if you close the table and run it again, is the value still
500 for PS)?
Yes.
What is the new sum? What was the old sum (section 5.4.1)? What is the
difference?
New: 500
Old: 185
Diff: 315
Can you identify the line that may have changed the sum?
No.
When the FlowField was changed, this record must have been inserted.
2-72 Navision Attain Objects
What happened?
I was able to put in the value with all three decimal places.
What is displayed in the field if you enter the Amount 234.1 and press
Enter?
234.10
What is displayed in the field if you enter the Amount 234 and press Enter?
234.00
What is displayed in the field if you enter the Amount 234.110 and press
Enter?
234.11
Basic Tables 2-73
This section reviews the concepts of the chapter by asking you questions.
The answers are in the subsection Answers.
Questions
1 What two major items can you define within a table description?
2 What table property defines the default lookup form for the table?
3 What field property is used to force the user to enter a value into a
primary key field?
4 What number range can you use for new fields that you add to the
Customer table?
5 If you want to view customers in order by the city that they live in, what
would you have to change in the table description?
6 How could you change the Salesperson Code field in the Customer
table so that the user would only be able to lookup Salespeople that
have a Commission % larger than zero?
Answers
1 What two major items can you define within a table description?
2 What table property defines the default lookup form for the table?
LookupFormID
3 What field property is used to force the user to enter a value into a
primary key field?
4 What number range can you use for new fields that you add to the
Customer table?
50000 to 99999
5 If you want to view customers in order by the city that they live in, what
would you have to change in the table description?
Add a secondary key that contains the City field as the first field.
6 How could you change the Salesperson Code field in the Customer
table so that the user would only be able to lookup Salespeople that
have a Commission % larger than zero?
Add a table filter to the table relation property that filters the Salespeople
where Commission % > 0.
Basic Forms
Creating Buttons
Creating Subforms
Standard Navigation
Chapter Review
3-2 Navision Attain Objects
After you have created tables, the next step in developing a C/SIDE
application should be to design forms. Forms are used for entering
information into database tables and for retrieving and displaying
information from database tables. It is through forms that users generate
the events that determine the flow of the application.
Forms can be used to access one table at a time, or they can combine
information from a number of different tables. A form can display
information that is calculated on the fly as the form is displayed, and it can
contain information (such as a label) that is not related to any table, or
purely decorative elements (such as bitmap pictures).
The figure below shows the components of a form and how they are
related. This and the following chapters will explore each component in
depth.
Form Description
Form Properties
Triggers
Controls
Properties
Triggers
The controls on a form that is bound to a table are usually bound to fields in
the same table. There need not be a control for every field in the table, nor
do all controls on the form need to be bound to table fields – controls that
aren’t bound to fields are called unbound controls. An example is a
command button that causes the information on the form to be printed;
another is a control that contains a descriptive text. An important category
of unbound controls includes controls displaying information – based on the
underlying table or user-entered values – that is calculated as the form is
displayed.
The form itself also has properties. For example, you can specify whether
the form is to be used only for displaying information or whether it will be
possible to insert new records or update existing ones.
Properties are defined on the Properties window that can be edited when
the form is opened in the Form Designer.
In this section, you will learn how to create a blank form. This is not the
best way to create a form, but it will give you an appreciation for the Form
Wizard and the Field Menu (these are discussed in a later section).
You will start by creating a blank form. There is a Wizard that helps you
create forms, but you will use it later. The steps to create a blank form are:
5 Close, save, and compile the new form. Use the name ‘Blank Form’
and the ID 91100. You will be using this form in the following
exercises.
What is the value in the title bar of the form (this is usually the blue area at
the top of a form that has the Min, Max, and Close buttons on it)?
What happens when you click the Next button on the toolbar?
Run form 91100 (Blank Form) and answer the following questions.
What is the value in the title bar of the form (this is usually the blue area at
the top of a form that has the Min, Max, and Close buttons on it)?
What happens when you click the Next button on the toolbar?
In this exercise, you will add a text box, label and a checkbox to your blank
form. These are the most common controls that you see on a form.
2 Click on the Toolbox button on the toolbar (or View, Toolbox). The
Toolbox window appears.
3 Hold your mouse over each button on the Toolbox window for a few
seconds. This will show you the Tool Tip for that button. The Tool Tip
displays the name of the control that the button represents.
4 Click on the Text Box button on the Toolbox window. This selects this
control type (the button stays down). To unselect this control type, you
can click on the Arrow button at the top left of the Toolbox window.
3-8 Navision Attain Objects
5 With the Text Box button selected, move the cursor (mouse pointer)
over the blank form. Your cursor should change to the cross hairs and
a box.
6 Click somewhere in the middle of the form. Notice that where you click
is where the upper left corner of the Text Box is located. If you drag
the mouse with the mouse button still down, you will change the size
of the Text Box as you are creating it. This is usually not useful.
You now have a Text Box on your form. What information will it display?
The Text Box control must be bound to a field or other data element (this
could be anything that returns a valid value: variable, function, or other
expression).
quotes).
5 Run the form and test your new Text Box by moving to the next,
previous, first or last record.
Adding a Label
There is only one problem that someone using your very simple form might
have. The user may not know what is being displayed. To help your user,
you will add a label that describes the field on the form.
1 In the Toolbox window, click Label (remember to use the Tool Tips to
help you find the right button).
2 Move the cursor over the form and click somewhere to the left of the
Text Box control that you added.
6 Run the form and test your new Text Box by moving to the next,
previous, first or last record. The label lets you know what field you are
looking at.
Adding a CheckBox
2 With the Checkbox button selected, move the cursor (mouse pointer)
over the blank form.
3 Click somewhere in the middle of the form below the other controls.
Notice that where you click is where the upper left corner of the
Checkbox is located.
4 Like the Text Box, the Checkbox control must be bound to a field or
other expression. For a Checkbox to work correctly, however, the
expression or field that it is bound to must return a Boolean value (true
or false). A check in the box represents true, and an empty box
represents false.
7 A Checkbox has a built-in label. So, change the Caption property also
to Blocked.
10 Run the form and test your new Checkbox by moving to the next,
previous, first or last record. You will also want to check and uncheck
the box.
Basic Forms 3-11
There are two very useful options on the bottom of the Toolbox window
that can help you quickly design your forms. The first is the Add Label
option. It allows you to attach a label automatically when you put another
type of control onto the form like a Text Box. The second is the Lock option.
It allows you to quickly add more than one control at a time.
2 Click on the Toolbox button on the toolbar (or View, Toolbox). The
Toolbox window appears.
3 Click on the Add Label button (bottom right). Notice that this button
stays down. To unselect it (bring it back up) you can click it again. It
will stay down until you unselect it or leave the Form Designer.
4 Click on the Text Box button. Notice that the Add Label button is still
selected.
5 Move the cursor over to the form (under the other controls) and click
to put the Text Box on the form.
How can you move just the Text Box (hint: look for the hand cursor)?
What happens if you click on the Checkbox button and then click on the
form?
Using Lock
3 Click on the Lock button (bottom left). Notice that this button stays
down. To unselect it (bring it back up) you can click it again. It will stay
down until you unselect it or leave the Form Designer.
4 Click on the Text Box button. Notice that the Lock button is still
selected.
5 Move the cursor over to the form (under the other controls) and click
to put the Text Box on the form.
Can you move any of the controls with the Lock button selected?
9 Delete the controls that you added for this exercise by selecting them
one at a time and pressing the DELETE key or by using a Marquee
selection to select them all and then pressing the DELETE key. For
more information about selecting controls, see the manual Application
Designer’s Guide.
Design the form one more time and use both the Add Label button and the
Lock button to add Text Boxes. Experiment with both of these until you are
comfortable.
Remember to remove any unbound controls before trying to save the form.
Multilanguage Functionality
be shown until the form is compiled. New Forms will need the Form
CaptionML populated also.
Basic Forms 3-15
In this section, you will create and use various types of controls. You will
start again with a blank form.
For some of these exercises, you will need to create a new item record.
The following will guide you to creating that record.
6 When instructed to find Item 1000, you should find the item you just
created.
In this exercise, you will add container controls to your blank form. You get
to use the Tab, Frame, and the Table Box controls.
1 Create a blank form as in exercise 3.2.1. Use the name ‘Blank Form 2’
and the ID 91200.
2 Follow the steps in exercise 3.2.2 to set the SourceTable to Item (the
Customer table is not useful for some of the exercises).
3 Move the cursor over the top left area of the form.
4 Click to create the Tab control. Notice that it has only one tab. The
name of the first tab is General. This name is a standard for forms that
have Tab controls.
1 Click the first tab on the Tab Control (any tab will do). This may select
the Tab control or it may simply change to that tab.
2 To assure that the Tab control is selected, click the first tab again.
1 Click the Tab that you want to add the control to. In this case, click on
the Test tab.
3 Click on the Tab where you want the control to be. You can move the
control if you need to.
What happens if you click on the General tab and back to the Test tab?
3-18 Navision Attain Objects
4 Edit the PageNames property of the Tab control so that it looks like
General,Frame,Table Box. Where is the label control now?
5 Move the label control to the bottom of the form (off of the Tab
control). What happens when you change to the General tab and back
now?
6 Click on the General tab and move the label from the bottom of the
form to the middle of the page for the General tab. What happens
when you change to the Frame tab and back?
3 Click in the middle of the page for the Frame tab. A frame should be
created.
3 Click in the middle of the tab to create the TableBox. You may want to
move it to the upper left corner. Notice that the TableBox is empty.
Remember that it is a container control. We still need to add other
controls to it.
3-20 Navision Attain Objects
The most common control that you see in a TableBox is a Text Box.
5 Click on the TableBox. The Text Box control becomes a column and a
Label control is added to the top for a column heading.
What happens to the title bar of the form if you click on another row in the
TableBox?
Autosizing Controls
It would be better if the tab control grew with the form. The TableBox
should also grow with the form. We will adjust the “glue” properties of the
controls to allow this.
6 Select the TableBox control by clicking on the TableBox tab and then
clicking the upper left gray box in the TableBox control.
11 Run the form. What happens now when you resize the form by making
it bigger?
Option fields can be displayed to the user in two different ways. You can
use a Text Box control (which can display almost anything) or you can use
option buttons (also known as radio buttons). In this exercise, you will
explore both.
3-22 Navision Attain Objects
6 Move down and click again to create the last Option button. There are
five option values for the Costing Method field. You will only allow the
user to access three of the values. That is why you need three Option
buttons. Each Option button represents one value of the Costing
Method field.
10 For the first Option button, change the Caption property to FIFO.
12 For the second Option button, change the Caption property to LIFO.
14 For the third Option button, change the Caption property to Specific.
What happens if you change the Text Box that is bound to the Costing
Method field to Specific?
What happens if you change the Text Box that is bound to the Costing
Method field to Average?
For this exercise, you will create a way for the user to easily see the
percentage of profit that they make on each item. You will use a vertical
progress bar that goes from 0 to 100.
8 Increase the height of the Indicator control by dragging the top edge.
Use the Next button to look at many different records. What range of values
did you notice?
What happens if you change the MaxValue property to 1000 and run the
form again?
BLOB fields are used primarily to store pictures. Some items in the Item
table have pictures. You will add a control to your form to display the
picture to the user.
3 Add a tab to the Tab control called Picture. Make sure this is the last
tab on the control.
3-26 Navision Attain Objects
6 Click in the middle of the tab to create the PictureBox control. Don’t
worry about the size. The default size will work fine for this example.
Use the Next button to look at many different records. List some of the
items that have pictures?
Basic Forms 3-27
In this section, you will learn easier ways of creating and modifying forms.
Always keep in mind what you learned in the previous sections so that you
understand what is really being done for you.
The form wizard can create two different types of forms – Card forms and
Tabular forms.
A card form is a form that displays one record at a time to the user. It
usually has a tab control, and the first tab is normally called ‘General’. In
this exercise, you will create a card form using the wizard.
3 Enter 18 in the Table field. You are creating a new Customer Card
form.
Anytime during the creation of the form in the Wizard, you can press
Preview on the bottom of the Wizard to view what you will be creating.
3-28 Navision Attain Objects
2 Leave Yes selected. Notice that the first tab is called General by
default.
3 Click in the empty line under General and enter Second Tab.
4 Click Next.
Which fields from the Customer table do you want on the tabs?
5 Click on the Second Tab tab. Notice that the form has both of the tabs
that you requested.
7 Double click the following fields: No., Name, Address and City.
These fields are moved onto the General tab.
8 Click on the Second Tab tab. Notice the Field Order list is empty for
this tab.
10 Click Finish to end the wizard and open the newly created form in the
Form Designer. The form has not been saved yet.
11 Close, save and compile the form with the ID 91300 and the Name My
Customer Card.
A tabular form is a form that displays many records at a time to the user. It
usually has a Tablebox control. In this exercise, you will create a tabular
form using the wizard.
3 Enter 18 in the Table field. You are creating a new Customer List
form.
Anytime during the creation of the form in the Wizard, you can press
Preview at the bottom of the Wizard to view what you are creating. Notice
that there is only one screen in this wizard. When you are finished in this
screen, you are done with the wizard.
3-30 Navision Attain Objects
1 Which fields from the Customer table do you want on your form?
2 Double click the following fields: No., Name, Address and City.
3 Click Finish to end the wizard and open the newly created form in the
Form Designer. The form has not been saved yet.
4 Close, save and compile the form with the ID 91301 and the Name My
Customer List.
Unlike the real Customer List form, this form allows the user to change the
values. This is not desirable because a list form is used for searching and
selecting records. You need to change the form so that it is not editable.
You could change every control, but that would still allow deletions and
inserts.
What happens?
In this exercise, you will add fields to your card form and your list form.
Note
The Field Menu can be used to add fields to any bound form, whether you
used the wizard to create the form or not.
2 On the toolbar, click the Field Menu button to open the Field Menu
window.
4 Click the gray box beside the Balance field to select the field (it should
be highlighted in blue).
5 Move the mouse over the form where you want the field to be.
6 Click to create a Text Box for the field. The SourceExpr property is
already set for you.
What else got placed on the form with the Text Box?
2 On the toolbar, click the Field Menu button to open the Field Menu
window.
4 Click the gray box beside the Balance field to select the field (it should
be highlighted in blue).
5 Move the mouse over the Tablebox where you want the new column
to be.
6 Click to create a new column for the field. The SourceExpr property is
already set for you.
Basic Forms 3-33
Do you think that most users will need to see the Balance field on this
form?
Because most users don’t need to see the customer’s balance, the column
should be made invisible on the List form by default. However, every user
should be able to add it.
In this exercise, you will change the List form so that it accommodates the
requirements mentioned above.
6 Click View, Show Column. Is the Balance field listed? Is the Net
Change field listed?
Why is the Balance field listed and the Net Change field not?
7 Check the box next to the Balance field and Click OK. Is the Balance
field shown now?
In this section, you will learn about the most important control that you will
have to add to almost all forms (the wizard won’t do this for you). This
control is the button.
You will explore the main two types of buttons – Command Buttons and
Menu Buttons.
In this exercise, you will create a command button that closes the form.
4 Move the mouse over the bottom right of the form (to the left of the
Help button).
10 Run the form again. Resize the form slowly. What happens to your
new button?
In this exercise, you create a push button that runs another form.
button.
3 Change the caption of the button to ‘Card’. Don’t forget to change the
glue properties as well.
8 Run the form again. What happens this time when you click the Card
button?
9 Close the card form. Select customer 50000 on the list form. Click the
Card button. Which customer is displayed on the card form?
In this exercise, you will change the Card button so that it opens the card
form with the record that is selected on the list form. This is called linking.
2 Open the Properties window for the Card button. Just below the
RunObject property are the RunForm properties. These properties
allow you to control the form that the button runs.
What happens when you click the Card button when customer 50000 is
selected?
What happens if you close the card form, select another customer and click
the Card button again?
Basic Forms 3-39
Notice that while the card form is open, you can click back on the list form
and choose another record. What happens to the card form when you
change the list form in this way?
7 Save your changes and run the form. Now, what happens when you
change the list form while the card form is still open?
Menu buttons are containers for menu items. A menu item is almost
identical to a command button (they share many properties).
5 Change the caption of the menu button to Customer. Most card and
list forms contain a menu button with the name of the table.
3-40 Navision Attain Objects
6 Make sure to change the glue properties on the button as you did with
the other buttons.
In this exercise, you will add menu items to your menu button.
4 In the Caption field in the first empty line, enter the word Card.
5 Instead of entering the rest of the values on the line, open the
Properties window for the menu item.
2 Add a menu button to the form with the caption Customer as in one of
the previous exercises.
3 Add a menu item to the menu button that has a caption of List.
Why does that form come up and not your customer list form?
In this section, you will learn how to display information from another table
on a form (not the source table of the form). One way to accomplish this is
to display another form within the first form. This is called a subform. Here
you will explore the subform control.
You will build two forms that come together to show the customer records
and the customer comments on one form.
In this exercise, you will create the main form. It will display customer
information and include a subform control that displays comments for the
customer.
3 Create a card form using the wizard that contains the customer
number, name, address, city, state and zip code on one tab named
General. See exercise 3.3 for more information on using the wizard.
4 Once the form wizard is done, save and compile the form with the ID
91500 and the name Customer Comment.
5 Make room for the Subform control by making the form larger (not
wider) and moving the Help button down to the bottom right corner.
There should be almost as much room on the form for the Subform
control as there is for the Tab control.
6 Create a Subform control on the form from the Toolbox window. The
control should be positioned just below the tab control and should be
exactly the same width. Adjust the height of the subform control to
take up the available space.
7 Open the Properties window for the Subform control and write down
the Height and Width properties.
Height ____________________
Width _____________________
3-44 Navision Attain Objects
In this exercise, you will create the form that displays the comment lines for
the customer. It will be a worksheet form that fits into the subform control
on the Customer Comment form.
3 Create a tabular form using the wizard that contains the Table Name,
No., Line No., Date and Comment fields from the Comment Line
table (the Code field is not needed). See exercise 3.3 for more
information on using the wizard.
4 To make this into a sub form, you must delete all buttons (OK, Cancel,
and Help). You must also move the table box into the upper left corner
and make the form the same size as the table box control.
Basic Forms 3-45
5 Close, save and compile the form with the ID 91501 and the name
Customer Comment Subform.
What property of the form could you use to automatically fill in the Line No.
field for you?
In this exercise, you will add the subform to the main form by setting up the
subform control.
Now, what appears in the spot where the subform control is?
Does the Customer Comment Subform fit into the subform control perfectly
(is it lined up with the tab control)?
What records show up in the subform when you change to a new customer
on the main form?
Here is a list of the things that you need to do to finish this combination of
forms:
6 Change the Width and Height properties of the Tablebox control (on
the subform) to the values that you wrote down earlier.
7 Display the records in the subform that match the customer record in
the main form.
11 Delete the Table Name, No. and Line No. fields from the subform.
This section describes the types of windows that the user sees in C/SIDE.
It then describes the types of forms that you will create in your applications
and gives examples and characteristics of each.
Dialogs
These are simple windows that display information and whose only
responses consist of pressing a button, whether it is OK, Cancel, Yes, No
and so on. These are generated by C/AL functions such as ERROR,
MESSAGE, TESTFIELD, CONFIRM and so on, or are created by the
programmer using a variable of type Dialog. They are not associated with
Form Objects.
Request Panels
These are found only within Report Objects and are not associated with
Form Objects.
Unbound Forms
These are Form Objects that are not associated with a table. They, like
Request Panels, are used when a few questions need to be asked of a
user in order to continue processing.
One-Record Forms
These are Form Objects that are associated with a table. They let the user
see and possibly edit only one record from one table at a time. An example
of this would be a Card Form.
Multi-Record Forms
These are Form Objects that are associated with a table. They let the user
see multiple records from one table at once and possibly edit them.
Examples of these include Tabular Forms, TrendScape Forms and Matrix
Forms.
3-50 Navision Attain Objects
Our Focus
The forms that make up the Building Blocks of Attain are those Form
Objects that are associated with tables (the last two listed above). While
important, the other forms and windows are not covered in this section.
Note that while C/SIDE lets you create forms of many kinds with many
different looks and methods of operation, the Navision Attain application
only uses a few of the possibilities. This is to provide a consistent look and
feel to the application.
It is strongly recommended that for ease of use and for consistency, you
also follow this policy for all modifications to Navision Attain and for any
application that interfaces with it. All of the following descriptions assume
full use of the Navision Attain standards.
A Card form lets the user view and edit one record at a time in a table. It is
used when there are too many fields, to view them all conveniently on only
one line. Card forms always have tabs (like index tabs) across the top
edge, with which the user can select different groups of fields to display.
Even if there are few fields, there is at least one General tab, which is
always first.
The table's Primary Key field is always the first field in the General tab. In
tables that use Card forms, there is only one field in the Primary Key.
Card forms are named with the name of the table they are associated with,
followed by the word "Card".
For example, the card form associated with the Customer table is called the
Customer Card. Card Forms also have at least one Menu Button at the
bottom named with the name of the table that provides ways of getting to
related information.
A Statistics form is a one-record form that lets the user view but not edit
information. It usually contains FlowFields, which lets the user drill down to
get to more information. Usually, it also contains calculated or derived
information contained in variables, which cannot be drilled down.
Statistics Forms can also contain tabs, in order to help organize the
information.
The table's Primary Key is displayed only in the form's title bar.
3-52 Navision Attain Objects
Statistics forms are named with the name of the table with which they are
associated, followed by the word "Statistics".
For example, the statistics form associated with the Customer table is
called Customer Statistics.
Entry Statistics forms are a special version of the statistics form. They are
named with the name of the table they are associated with, followed by the
words "Entry Statistics". For example, Customer Entry Statistics.
A Tabular form is a multi-record form that lets the user view multiple
records from a table and edit them. Each record is displayed as a single
row in the tabular form and each field is displayed as a column forming a
spreadsheet-like table within the form itself.
Tabular forms are named with the plural of the name of the table with which
they are associated.
For example, the Tabular Form associated with the Country table is called
Countries.
In the case of associated tables that have multiple fields in the Primary
Key, the name can be different. For example, the Tabular Form associated
with the General Posting Setup table is called General Posting Setup.
A List form is a multi-record form that lets the user view multiple records
from a table at once, but not edit them. It uses the same rows-and-columns
look as the Tabular Form.
The Primary Key field(s) of the associated table is (are) displayed in the
left-most column.
Basic Forms 3-53
List Forms are named with the name of the table with which they are
associated, followed by the word "List". For example, the list form
associated with the Customer table is called Customer List.
A more specialized version of the List Form is the Ledger Form. These are
used only for Ledger Entry tables. They differ from ordinary List Forms, in
that even though users cannot insert or delete records, they can sometimes
edit a small number of the fields.
Also, the Primary Key, always an integer named "Entry No.", is displayed in
the right-most column rather than the left-most column.
Finally, the Ledger Form is named with the plural of the name of the
associated table. For example, the Ledger Form associated with the
Customer Ledger Entry table is called Customer Ledger Entries.
This is done using the AutoSplitKey property of the form, combined with an
integer as the last field in the table's Primary Key.
The Primary Key fields of the associated table do not display on the
Worksheet Form.
Many forms within Navision Attain have characteristics of both a card form
and a tabular form, for example the Sales Invoice form.
3-54 Navision Attain Objects
The fields that are common to the entire invoice are located on a card-like
form with tabs, showing one invoice at a time. However, the invoice lines
display in a table-like section of the form, where multiple invoice lines (from
the same invoice) can be viewed at the same time and edited. These are
called "Header/Line" forms.
Header/Line forms are, in fact, two separate forms associated with two
different tables. The main form is a Card Form associated with a table. The
main form has a sub-form control. A Worksheet Form is displayed within
the sub-form control that is associated with a different table, a table that is
"subsidiary" to the first (you'll learn more later). The sub-form control
handles the linkage between the two forms.
In the example above, the Sales Invoice form, the name of the form will be
the name of the Document that it represents. In other cases, the name of
the form will be whatever the name of the main form would have been
without the sub-form.
These situations are described in more detail when we discuss the Table
building blocks.
A Setup form is a one-record form that lets the user view and edit the one
and only one record in a setup table. The user is not allowed to insert or
delete this record using this form. Since there are many fields, these forms
contain tabs (like index tabs) across the top edge to organize the
information.
Since there is only one record, the Primary Key does not display anywhere
on this form.
Setup forms are named with the name of the table they are associated
with. For example, the setup form associated with the General Ledger
Setup table is called General Ledger Setup.
Basic Forms 3-55
A Menu form is a non-bound form (not related to any table) that lets the
user access many of the other form types for a functional area from the
main menu.
Menu forms are named with the name of the functional area they are
associated with plus the word “Menu”. For example, the menu form
associated with the General Ledger functional area is called General
Ledger Menu.
There are other forms that let users view and/or edit multiple records at the
same time. These include TrendScape forms and Matrix forms. These
forms allow great functionality within Navision Attain, but like a patio on a
house, they do not impact the main architecture of the system.
3-56 Navision Attain Objects
This section is here to describe the normal ways that a user can go to one
form from another. We described the mechanics of this in the previous
section Extending the Functionality of Your Forms.
Here we will simply mention the standard navigation that must be provided
for consistency throughout the application.
Most master tables will have both a card and a list form. Since both of
these forms access the same table, there are many standards concerning
what each form must do.
• The user must be able to view and edit one record at a time on the
card form.
• The user must be able to view (not edit) all records on the list form. By
making this form non-editable, the user can begin a search by typing in
a particular column.
• The user must be able to bring up the list form from the card form in
the following ways – F5, List menu item (on the menu button that has
the same name as the table) and the Lookup button on the tool bar. In
this case, the user should be able to select a new master record and
press the OK button to exit the list form and change the original card
form to the selected master record.
• The user must be able to open a new card from the list form (by
pressing SHIFT+F5 or clicking the Card menu item on the menu button
that has the same name as the table) that displays the master record
selected on the list form.
As mentioned above, most master tables will have a card and a list form.
Many master tables also have a statistics form. The user should be able to
get to this form from either the card or the list forms in exactly the same
way.
The standard way of getting to the statistics form is with the shortcut key F9
or the Statistics menu item (on the menu button that has the same name as
the table).
Basic Forms 3-57
Every master table has at least (usually only) one ledger table. From the
master forms (card, list and statistics), the user must be able to get to the
ledger form. The user can get there in the three different ways – as a result
of a drilldown button on a FlowField, using CTRL+F5, or the Ledger Entries
menu item (on the menu button that has the same name as the table).
If a drilldown button was pushed, only the records used to create the
calculated value are displayed (this is a function of the built in drilldown
functionality). If the shortcut key or the menu item is used, all ledger
records for this particular master are shown. This requires a RunFormLink
on the menu item that links the two tables. You will also want to keep the
two forms synchronized whenever the master form is updated. For this, you
should also change the RunFormLinkType property to OnUpdate.
Note
Journal Forms
Every journal form has similar buttons at the bottom of the form. These
buttons allow the user to either navigate to another form or perform a task.
• A menu button named after the master table for the functional area.
This menu button must contain menu item s that lets the user go
directly to the card form for the master table or go directly to the ledger
form for the ledger entries. In both cases, the form brought up should
be linked to the master table record that the journal line is associated
with.
• A menu button named “Posting”. This menu button should contain the
following menu items related to posting the journal lines – Post, Post
and Print, Test Report.
3-58 Navision Attain Objects
No questions here.
What is the value in the title bar of the form (this is usually the blue area at
the top of a form that has the Min, Max, and Close buttons on it)?
What happens when you click the Next button on the toolbar?
It changes the title bar of the form to the next customer in the customer
table.
You now have a Text Box on your form. What information will it display?
None.
Run the form and test your new Text Box by moving to the next, previous,
first or last record.
The text box should display the No. field from the customer table.
Adding a Label
Run the form and test your new Text Box by moving to the next, previous,
first or last record. The label let’s you know what field you are looking at.
The text box should display the No. field from the customer table.
Basic Forms 3-59
Adding a CheckBox
Run the form and test your new Checkbox by moving to the next, previous,
first or last record. You will also want to check and uncheck the box.
How can you move just the Text Box (hint: look for the hand cursor)?
Select the Textbox and move the mouse over the edge of the selection until
the hand cursor appears. With the hand cursor showing, you can click and
drag just the Textbox.
What happens if you click on the Checkbox button and then click on the
form?
Using Lock
Can you move any of the controls with the Lock button selected?
Three new tabs were added Test, Frame and Table Box.
What happens if you click on the General tab and back to the Test tab?
The control disappears when the General tab is selected and reappears
when the Test tab is selected.
Edit the PageNames property of the Tab control so that it looks like
General,Frame,Table Box. Where is the label control now?
Move the label control to the bottom of the form (off of the Tab control).
What happens when you change to the General tab and back now?
Click on the General tab and move the label from the bottom of the form to
the middle of the General Tab. What happens when you change to the
Frame tab and back?
The control disappears when the Frame tab is selected and reappears
when the General tab is selected. It is again on a page in the tab control.
Several rows of records from the item table. There is a triangle in the gray
box next to the current row.
What happens to the title bar of the form if you click on another row in the
TableBox?
The controls all stay the same size and in the same location.
Autosizing Controls
Run the form. What happens now when you resize the form by making it
bigger?
The tab control and the table box grow with the form.
A DropDown button.
One.
What happens if you change the Text Box that is bound to the Costing
Method field to Specific?
What happens if you change the Text Box that is bound to the Costing
Method field to Average?
None of the buttons are selected because there is no button for Average.
Use the next button to look at many different records. What range of values
did you notice?
What happens if you change the MaxValue property to 1000 and run the
form again?
The values in the indicator are almost invisible. The percentage changes to
less than 1.
Use the next button to look at many different records. List some of the
items that have pictures?
No questions here.
No questions here.
What happens?
Basic Forms 3-63
The Find window appears and begins searching for what I type.
The user does not have to remember how to open the Find window. They
can simply click on a column and begin typing. It is faster.
Yes.
What else got placed on the form with the Text Box?
Yes.
Do you think that most users will need to see the Balance field on this
form?
No. Only certain users will use this field on this form.
No.
Click View, Show Column. Is the Balance field listed? Is the Net Change
field listed?
Why is the Balance field listed and the Net Change field not?
The Net Change field has not been added to the form. Only fields that have
been added to actual form appear here.
Check the box next to the Balance field and Click OK. Is the Balance field
shown now?
Yes.
The Balance field is still on the form so the user can see it.
OK.
Run the form again. Resize the form slowly. What happens to your new
button?
It stays where it is and does not stay next to the Help button.
Test the form again by resizing it. What happens to your new button?
It stays beside the Help button in the bottom right corner of the form.
It is exactly where is was put, but the OK and Cancel buttons are gone.
Basic Forms 3-65
Nothing.
Run the form again. What happens this time when you click the Card
button?
Close the card form. Select customer 50000 on the list form. Click the Card
button. Which customer is displayed on the card form?
What happens when you click the Card button with customer 50000
selected?
What happens if you close the card form, select another customer and click
the Card button, again?
Notice that while the card form is open, you can click back on the list form
and choose another record. What happens to the card form when you
change the list form in this way?
Design the form and change the RunFormLinkType property of the Card
button to OnUpdate. Save your changes and run the form. Now, what
happens when you change the list form while the card form is still open?
It changes to the new customer as well. It stays linked every time the list
form is updated.
3-66 Navision Attain Objects
Nothing.
A menu of the menu items that I added shows up below the menu button.
The card form opens with the record selected. Same as clicking the menu
item.
Why does that form come up and not your customer list form?
The default lookup form for the customer table is the Customer List form.
My Customer List is not setup as the default lookup form. It is the
LookupformID property of the customer table that tells the system which
form to bring up.
Open the properties window for the Subform control and write down the
Height and Width properties.
Height 5500
Basic Forms 3-67
Width 9350
Nothing.
What property of the form could you use to automatically fill in the Line No.
field for you?
AutoSplitKey
This table can hold comments from many master tables. The Table Name
changes the table relation of the No. field to the appropriate master table.
Now, what appears in the spot where the subform control is?
Form 91501
Does the Customer Comment Subform fit into the subform control perfectly
(is it lined up with the tab control)?
It is not perfect. The width is not correct. The scroll bars on the right and
bottom do not appear in the normal place.
The Tab control expands and goes under the subform control. The subform
control still does not expand.
What records show up in the subform when you change to a new customer
on the main form?
3-68 Navision Attain Objects
No.
Yes.
Yes.
The subform changes so that I only see the comments for the new
customer.
Basic Forms 3-69
In this section, you will be asked questions about the material covered in
this chapter. Answers to the questions can be found in the subsection
Answers.
Questions
Which property must you set on Command button for the RunObject
property to work?
Which control allows a form to display more than one record at a time?
How do you attach a label to another control so that the label follows the
other control if you move it?
3-70 Navision Attain Objects
Answers
False. Some forms are not related to any table (unbound). For example the
Main Menu form.
False. Most forms can be created with the wizard. The only additional items
that must be added are usually buttons.
Which property must you set on Command button for the RunObject
property to work?
Which control allows a form to display more than one record at a time?
Tablebox
Subform
SourceExpr
SourceTable
Indent other menu items under it using the Right button on the Menu
Designer window.
How do you attach a label to another control so that the label follows the
other control, if you move it?
Click the Add Label button on the Toolbox window before you add the other
control.
Basic Reports
Reports
Totaling in a Report
Types of Reports
Chapter Review
4-2 Navision Attain Objects
4.1 REPORTS
Report Description
Properties
Triggers
Data Items
Properties
Triggers
Sections
Properties
Triggers
Controls
Properties
Request Form
Properties
Triggers
Controls
Properties
Triggers
Basic Reports 4-3
Report Description
This is the total description of the report – how data is collected and how
data is presented on paper when the report is run. The report description is
stored in the database.
Data Item
Section
In a printing report, each data item could have one or more sections. A
section can be thought of as a block of information to print on the paper.
The complete report consists of a number of sections; some that are
printed only once like a grand total, some that are printed once per page,
for example a header, and some that are printed for each record that is
retrieved from the database.
Control
Request Form
A request form is a form that is run before the actual report begins
execution. It is used to gather requests and options from the user of the
report–for example, sort order or level of detail.
4-4 Navision Attain Objects
Property
Trigger
There are two sides to designing a report: defining the logical structure, the
data model and designing the visual layout.
Defining the data model means defining how the data for the report is
collected. This includes:
• Defining the tables the report will use by creating data items.
• Defining relationships between data items if the report uses more than
one table.
• Defining the key, sort order and filters to use with the involved data
items.
• Defining which elements the user will be able to change at run time.
Data Items
The data model of a report is built from data items. A data item
corresponds to a table. When the report is run (see the diagram on page
214), each data item is iterated for all records in the underlying table. When
Basic Reports 4-5
a report is based on more than one table, you establish a hierarchy of data
items to control how the information is gathered by indenting data items.
Example
In order to make a report that prints out a list of customers and for each
customer lists sales orders placed by that customer, you will define two
data items – one that corresponds to the Customer table and one that
corresponds to the Sales Order table. The second data item is indented –
as the report works its way through the records in the Customer table, for
each customer all sales orders that are related to this customer must be
found by going through the records in the Sales Order table.
Sections
Sales Statistics
Header CRONUS International Inc.
Customer: No.: 10000..30000
Sections
30000 Lauritzen
Kontormøbler A/S
Sales (LCY) 13,676.20 0.00 0.00 0.00 0.00
Profit (LCY) 2,444.20 0.00 0.00 0.00 0.00
Profit % 17.9 0.0 0.0 0.0 0.0
Inv. Discounts (LCY) 0.00 0.00 0.00 0.00 0.00
Pmt. Discounts (LCY) 0.00 0.00 0.00 0.00 0.00
Total
Sales (LCY) 72,710.20 0.00 0.00 0.00 0.00
Footer Profit (LCY) 15,434.20 0.00 0.00 0.00 0.00
Profit % 21.2 0.0 0.0 0.0 0.0
Sections
Inv. Discounts (LCY) 0.00 0.00 0.00 0.00 0.00
Pmt. Discounts (LCY) 0.00 0.00 0.00 0.00 0.00
This report prints sales statistics information and retrieves all its data from
one table. It demonstrates a range of the features that are available for
designing reports.
• After all records (all records that were selected by the filter that is) have
been printed, a footer section is printed that contains totals for the
selected customers.
• In the body section and in the footer section, a filter has been applied
to create columns where data are collected and totaled for different
periods.
Basic Reports 4-7
When you select a report in the Object Designer and press the Design
button, you are taken into the Report Designer.
In the Report Designer window, you define the Data Model by adding Data
items.
In the Report Designer window, you can specify the tables that the report
will read. It is important to note that any table mentioned here will be read
in its entirety during the report. In order to limit the number of records read,
you should link and filter Data items. You could actually read the same
table more than once in the same report by listing it more than once in the
Report Designer. For example, you may want to read customers that are
not blocked first and then customers that are blocked.
The tables that you list become Data items in the report. Data items are
record variables (just like you would use in code) that allow the report to
access the data of a table.
The right column in the Report Designer is the Name that the Data item will
go by throughout the report. Like all variable names, these names should
be unique within the report.
You can use the Report Designer to specify how the report engine should
read the underlying tables:
The order in which the Data items are listed, is the order that the report will
read the data from the tables. At the bottom of the Report Designer
window there are four arrow buttons. You can use the up and down arrow
buttons to reorder the Data items.
You can use the right and left buttons to indent or unindent a Data item.
Indenting a Data item under another Data item affects the report in this
way:
4-8 Navision Attain Objects
• For every record read from the top Data item, all the records will be
read from the indented Data item (this takes into account any filters or
links). (This is similar to a nested FOR loop.)
Note
A proper key should be selected for the indented data item. It should
contain the fields that are being used to link the data item.
This exercise will help you understand some of the basic design principles
of creating a Navision Report. In this half of the exercise, you will create the
data model in the Report Designer.
2 Click New. The New Report window appears. You will not be using
the Report Wizard because it limits you to one table.
Basic Reports 4-9
4 Select the first empty line in the Report Designer and enter the
number or name of the Salesperson/Purchaser table (13).
5 Select the next empty line in the Report Designer and enter the
number or name of the Customer table (18).
1 Indent the Customer data item by clicking the right arrow button at the
bottom of the form.
With the customer data item still selected, bring up the properties for that
data item.
3 Click on the DataItemLink property. You need to match the fields that
link the two tables.
5 In the Field column, select the Salesperson Code field from the
Customer table.
Whenever you link two data items, you should always sort the indented
data item accordingly. In this case, you should change the
DataItemTableView property of the Customer data item to
SORTING(Salesperson Code).
Close, save and compile the report with the ID 91200 and the name
Customers by Salesperson 1.
The data model is now complete. The next step is to design the page.
Before you do that, you need to know about the Section Designer.
As you recall, each data item can have one or more sections defined in the
report. The Section Designer lets you design the visual layout of the report
section by section. While you are in the Report Designer, select the View
menu and then Sections.
Basic Reports 4-11
Note
If the report has its Processing Only property set to Yes you cannot create
any sections. This property is discussed later with the other properties.
Each data item can have any number of sections (remember that every
section is a subobject of one of the Data items). Therefore, when you
create a section (F3), you must select the Data item that the section is
associated with and specify the type of section that you need. You can
delete a section by clicking on the gray bar and then pressing F4.
Section Description
Section Description
Each section works like a small form with the SourceTable property set to
the data item’s table. Controls on sections do not have any triggers but do
have the same properties as on a form.
Note
While you can see colors that you set for controls in the design of a section,
these colors will NOT be printed when you actually run the report. The only
way to print colors is to use Image or PictureBox controls.
In this exercise, you will define the sections and finish the report that you
started earlier.
2 On the main menu, click View, Sections. You should see two sections
that have already been created for you by the report:
• Salesperson/Purchaser body(1)
• Customer body(1).
Basic Reports 4-13
Salesperson/Purchaser Header(1).
You should now have four sections in your report. But they do not
have any controls on them. If you were to run the report, nothing
would be printed on the pages.
9 Hold down the CTRL key and select the Code and Name fields.
Notice that the labels and text boxes are created differently on a report
section than on a form. The labels are placed above the text boxes in
columns. Your labels are probably on top of the text boxes because
the section was too small to put them above the text boxes. You can
move the controls around just like you did with forms.
13 Drag the labels one at a time from the body section to the header
section and line them up with the corresponding text boxes.
14 Repeat steps 7-13 for the Customer body section. Add the No.,
Name, City, and Phone No. fields from the Customer table. Don’t
forget to move the labels to the header section.
Basic Reports 4-15
15 Close, save and compile the report. You do not have to save a report
before you run it, but it is a very good idea. You never know when
your computer might crash. Save regularly when designing reports!
16 Run the report. The request form appears. This form allows the user
to enter filters for the data items or change the sort of the data items.
They can also choose to Print the report or Preview the report.
17 Click Preview.
Note
If you do not have a printer driver loaded for Windows you will not be able
to print or preview any reports.
Does the report look the way you expected it to? Where do the header
sections print for each data item?
While you are in the Report Designer, you can select the View menu and
then Request Form.
Use the Request Options Form Designer to design the Options tab of the
Request Form. The request form is the form that is displayed to the user
when they run the report.
You cannot design the data item tabs or the buttons at the bottom of the
Request Form from here. This is just like any other form you create.
Remember that the Options tab will be the last tab on the Request Form.
When you add controls to this form, the Options tab will be displayed. The
Options tab will not be visible to the user until you add some controls.
You must usually include some triggers before you can utilize the Options
tab of the request form. As this course only deals with basic reports, you
will not be adding controls to the request form.
The other tabs of the request form can be changed via properties, as you
will see in the rest of this chapter.
Basic Reports 4-17
In this section, you learn how certain types of sections can be used and
when they are printed.
In this exercise you experiment with header, body and footer sections.
First, without indentation or linking, then, with indentation and finally with
linking.
No Indentation or Linking
2 Click New and the New Report window appears. You will not be using
the Report Wizard, because it limits you to one table.
4 Click the first empty line in the Report Designer and enter the number
or name of the Salesperson/Purchaser table (13).
5 Click the next empty line in the Report Designer and enter the number
or name of the Customer table (18). Do not indent or link the two data
items.
10 Insert a header for each data item. You should now have four
sections. Insert a footer for each data item as well.
11 On the Salesperson Body, place the Code and Name fields and drag
the labels to the header.
12 On the Customer Body place the No., Name, and Phone No. fields
and move the labels to the header.
4-18 Navision Attain Objects
13 On the Footer for each data item, place a label from the toolbox and
change the caption to SP-footer and Cust-Footer respectively.
14 Close, save and compile the report with the ID 91300 and the name
Basic Sections Test.
With Indentation
With Linking
4 Remember that you also need to set the sorting for the report. Add the
SalesPerson Code Key to the Customer table. Change the
DataItemTableView property to SORTING(Salesperson Code).
Notice that the Customers for some of the salespeople extend to more than
one page. However, on the second page, the report does not print any
headings, that tell us, what salesperson we are looking at. It would be nice
if we could get our headings printed on every page.
3 Select each of the Header sections on the report and change the
PrintOnEveryPage property to Yes.
Now, the Salesperson header and the Customer header appear at the top
of every page. This still doesn’t tell us which salesperson those customers
go with. What we need here is a section that will print at the top of just
those pages that are continuations of the previous page and show the
salesperson that we are currently on.
This is what a TransHeader does. First, you need to determine what data
item the TransHeader section goes with. You should ask yourself “which
data item is the report in the middle of printing when it goes to the next
page (where I want the TransHeader)?” The answer in your case is the
customer data item.
2 Insert a TransHeader section for the customer data item. Note that it
comes between the header and the body sections. In the Customer
TransHeader section, you need to display the current salesperson.
3 Click on the Salesperson Body section and select both the Code and
Name fields.
6 Click Edit, Paste to copy the two controls to this section. Line them up
with the ones that you copied. This will almost work. Because we are
Basic Reports 4-21
in a section of the customer data item now, we can not display fields
from another data item without specifying the data item first.
7 Select the Code text box control and open the Properties window.
9 Repeat this process for the Name text box. The value for the
SourceExpr property should be “Salesperson/Purchaser”.Name. You
will also want to add a label to this section that has the word
Continued in the caption.
Where did the TransHeader print (it will not be on every page)?
Transfooter
Where did the TransFooter print (it will not be on every page)?
Basic Reports 4-23
In this section, the exercises will help you understand some useful
properties. You will be slowly improving the report that you created in the
previous exercises.
Your user would like the Customer by Salesperson report to start a new
page every time it finds a new salesperson. There is a property designed
just for this - NewPagePerRecord.
When does a new page get created now (there are two times)?
You may now notice that the report does not contain any customers for
salesperson Alice Hart. She is not really a Salesperson. She is a
Purchaser. We need to change the report to only include those
Salespeople that actually have Customers. Remember that in this report
customer is the detail data item.
You user would like the report to allow filtering on the Code and Name
fields of the Salesperson/Purchaser table on the request form. The property
ReqFilterFields allows you to specify which fields the user can see on the
request form.
What else does the tab allow you to do to the data item?
You may also want to change the name of the tab (or the Heading) from
Salesperson/Purchaser to just Salesperson on the request form. The
property ReqFilterHeading allows you to change the name of the tab on the
request form.
Note
Sorting a data item that does not have ReqFilterFields causes its Tab on
the Request Form to disappear.
4-26 Navision Attain Objects
In this section, you will learn how to group data within a report.
What is Grouping?
Keep in mind that Grouping is not a necessity if you can use indentation to
link and filter your data items the way that you want. Grouping must be
used in cases where the field that you want to group on is not related to
another table.
The most common use for grouping is to subtotal a report by Date. Date
fields are not related to a table but do signify important groups within the
table. For example, you may want to look at Customer Ledger Entries by
Customer and for each Customer by date. You only need to Group on one
field – Date. You can “Group” (this is in quotations because while the term
is correct, here we are not actually talking about Grouping the report) the
entries by Customer using indentation.
Note
This property is the key to printing the special sections. You must specify
the fields that you want the report to monitor (or break on) in this property
to group the report. This property has nothing to do with Totals or with
indentation. The name of the property is somewhat misleading.
• First, the fields you specify in this property (and there can be more than
one) must also be in the key that you specify in the DataItemTableView
Basic Reports 4-27
• Second, you must create these special sections. The only thing that
Grouping does is print these sections at the correct time.
In this exercise, you will create a report with one data item and use
grouping to form breaks in the report.
2 Click Report.
3 Click New and the New Report window appears. You will not be using
the Report Wizard, although it could be used to create this report.
5 Select the first empty line in the Report Designer and enter the
number or name of the Cust. Ledger Entry table (21).
12 Select the Posting Date text box and drag it from the body section to
the Group Header section.
14 Close, save and compile the report with the ID 91500 and the name
Customer Detail.
Remember that you must sort the data item using the field(s) that you want
to group on. Unfortunately, there is no key in the Cust. Ledger Entry table
that starts with the Posting Date field. So, you will create a new key in the
underlying table. You might have to do this in many reports that you create.
Finishing Up
In this exercise, you will learn how grouping and indentation can work
together to group data at many different levels.
You will now change this report so that it groups the Customer Ledger
Entries first by Customer and then by posting date. Instead of trying to
add Customer No. to the GroupTotalFields property, you will use
indentation to group by Customer.
5 Insert (F3) a line above the Cust. Ledger Entry data item.
7 Indent the Cust. Ledger Entry data item once under the Customer
data item.
8 Change the DataItemLink property for the Cust. Ledger Entry data
item to “Customer No.” = FIELD(“No.”). You can use the assist-edit
button to help you set this property.
4-30 Navision Attain Objects
You must now insert a Header section for the Customer data item.
12 On the Customer body section add the No., Name, City, and Phone
No. fields.
You might want to move the controls on the Cust. Ledger Entry
sections over to the right to show the indentation that we are using.
You may Note the “>” symbol in the gray bar of the Ledger sections.
This signifies that this data item is indented. To do this, simply select
all the controls on a section and move them to the right as you would
on a form.
16 Click Preview.
Where did the Header sections print for each data item?
4-32 Navision Attain Objects
In this section, you will learn how to add totals to the footer sections in a
report. This is actually very easy, as you will see in the exercises.
What is Totaling?
Navision Attain uses Subtotals and Grandtotals. Subtotals come after some
logical grouping of records and sum the group. Grandtotals come at the
very end of the report and sum the entire report (all subtotals).
Before the report will calculate a total for you, you must tell the report which
fields it should total (sum). The TotalFields property of a data item allows
you to specify the fields that you want to sum. By naming a field in this
property, you are telling the report to keep up with totals for that field
throughout the report. This does not, however, tell the report to display the
totals.
To display the total amounts for the Fields you have specified in the
TotalFields property, you need to do two things:
• First, create a section to display the Totals. The report will only display
total amounts on some type of Footer section (Footer, GroupFooter,
TransFooter or TransHeader).
• Second, bring up the field menu for that section and drop the fields that
you are summing into that section. You may want to delete the labels
and line up the controls with the correct columns. That’s it. Because
you are displaying these fields on a Footer type of section, instead of
showing the current value of the fields, the report shows the total
amounts.
In this exercise, you add subtotals and grand totals to one of the reports
you created in Section 4.5.
Basic Reports 4-33
11 Line up the Amount field with the amount column. You may want to
change the font or make it bold as well.
15 Click Preview.
How did you tell the system that the Amount field on the Group Footer
section should show the total for just that group?
Exercise 4.6.2 Adding Subtotals and Grand Totals to Indented Data Items
In this exercise you will add subtotals to your report that has indentation
and grouping.
6 Insert a Group Footer and a Footer section for the Cust. Ledger Entry
data item.
8 Select the Amount field and add this field to the Group Footer section.
10 Line up the Amount field with the amount column. You may want to
change the font or make it bold as well.
14 Click Preview.
In this section, you will discover some of the interesting things that are
possible with reports. Some of these features require a line of code or two,
but you will be instructed exactly where to place the code.
You will learn how to use FlowFilters in reports, modify the request form,
skip sections, and perform grand totals with more than one data item.
In this exercise, you will add the ability to filter the report with the Date
Filter field in the Customer table. This exercise depends on the exercises
in section 4.6. You must complete those exercises before attempting these.
6 In the Filter column for the Date Filter field, enter the range
01/01/01..12/31/01.
7 Click Preview.
Are there any records on the report that are outside of that range?
13 In the Filter column for the Date Filter field, enter the range
01/01/01..12/31/01.
14 Click Preview.
Are there any records on the report that are outside of that range?
What happens to the report if you leave the Date Filter empty on the
request form?
Exercise 4.7.2 Adding and Taking Away from the Request Form
In this exercise, you will add a checkbox to the Options tab of the request
form and take away other tabs on the request form.
You may have noticed that not every data item seems to have a tab (on the
request form) on the reports that you’ve created. Actually, every data item
does have a tab but depending on certain properties the tab may or may
not appear on the request form.
Which two properties determine whether the user sees the tab for a data
item on the request form?
To add a data control to the Options tab of the request form, you first need
to create a global variable for the control to be bound to. The user will
change the value of the variable through the control. You will use the value
of the variable in the next exercise.
Basic Reports 4-39
3 Add a variable named ShowDetails and set the data type to Boolean.
5 Click View, Request Form and the Request Form Options Designer
appears.
6 Add a checkbox and label (use the Add Label button) to the form.
What value does the variable have when the box is checked?
What value does the variable have when the box is not checked?
Check the box and preview the report. Close the preview window and rerun
the report. Is the box still checked?
Every time the report is run, the variable is set to its default value of False.
To get the value to be remembered, you must tell the request form to save
4-40 Navision Attain Objects
Check the box and preview the report. Close the preview window and rerun
the report. Is the box still checked?
In this exercise, you will use the value of the variable that you added in the
previous exercise to display or not display a section on the printed report.
The section that you will conditionally show is the Cust. Ledger Entry Body
section.
3 Click on the Cust. Ledger Entry Body section’s gray bar. This selects
that section.
CurrReport.SHOWOUTPUT(ShowDetails);
10 Click Preview.
Does the report look the same as the last time you ran the report?
Close the preview window. Rerun the report and make sure the checkbox
is not checked on the Options tab.
Exercise 4.7.4 Adding a Grand Total with More Than One Data Item
In this exercise, you will add a grand total to the Customer Detail 2 report.
This is not possible without some amount of code. In this case, you will add
just one line of code to the report and, of course, a new section.
14 Click Preview.
Every caption on the request form or in the sections must have the
CaptionML and OptionCaptionML property populated. If not, your user will
see some captions in English and others in the language chosen on the
report and request form. Bound controls should already have this property
populated. However, any new fields to hold variables or calculated fields
will also need to have the OptionML populated. See Basic Tables for more
information on how to populate this property.
Basic Reports 4-43
In this section, you will learn about the types of reports that are found in a
normal functional area. The types of reports are not nearly so formal as the
types of forms or tables. This is just a brief outline that will help you in
further discussions about the system architecture.
List Reports
A List report contains a single DataItem that is the table that is being listed.
Each column contains a field from the table, and the data is printed from
that table, not brought in from other tables or calculated from other tables.
The name is usually the name of the table followed by the word "List", or
sometimes followed by the word "Listing".
Examples
• Customer Listing
• Item List
Test Reports
Its purpose is to test each of the Journal Lines according to the same
criteria that will be used for Posting, so that all of the errors can be found
and fixed before posting.
Once an error is found during posting, processing stops and the error must
be fixed before Posting can be attempted again.
Thus, in a journal with multiple errors, a test report is a good way of finding
these errors.
The name is usually the name of the corresponding Journal form followed
by the word "Test".
Examples
Posting Reports
A Posting report can be printed as part of the "post and print" option on a
Journal.
It is actually a report that is printed from the Register, and has the same
name as that Register.
It lists all of the transactions (that is, Ledger Entries) that have been posted
into that Register.
Examples
• G/L Register
• Item Register
• Payroll Register
Transaction Reports
The first is the Master table, and the second is the corresponding Ledger
table.
Normally, a Transaction Report lists all of the ledger entries for each record
in the Ledger table.
Normally, there is a subtotal for each Master table record, and a grand total
for all tables printed.
This report is used to view all transactions for a particular Master record.
Examples
Reports are more loosely defined than other application objects because
they are so often customized for a particular client. However, most reports
do consist of a tabular listing with records listed horizontally and each field
displaying in its own column. Many times, there will be some sort of group
heading or total to split the lines among various categories and subtotal the
lines by the categories.
Examples
Document Reports
Document reports are different from most other reports, in that, many of the
fields are not displayed in columns.
The lines for the invoice, print out more like a normal report in rows and
columns.
The lines correspond to the header on the same page, and lines from other
invoices do not display on the same page.
Examples
• Sales Invoice
• Customer Statement
• Purchase Order
4-46 Navision Attain Objects
In this exercise, you will test your abilities to create a simple report. There
are no step by step instructions in this section. Once you have tried this for
yourself, you may want to look at the step by step instructions in the
Answers to Questions section.
Here are the requirements for your report. Use the ID 91700 and the Name
Vendor Detail for this report.
• Displays No., Name, and Phone No. from the Vendor table.
Change that report to include another subtotal such as a subtotal for each
unique posting date that applies to a certain vendor. This will require
grouping on the Posting Date field. Don’t forget to choose an appropriate
key.
Change the report so that it doesn’t print vendors that do not have any
detail records.
Change the report so that it doesn’t print any Ledger records whose
Document type is Credit Memo. This will require filtering on that data item.
Remember that the word View means Sorting and Filtering.
Basic Reports 4-47
No questions here.
Does the report look like you expected it to? Where do the header sections
print for each data item?
Yes.
The Header section for the Salesperson data item only prints at the top of
the first page.
The Header section for the Customer data item prints after every
Salesperson body section, if that Salesperson has customers. It does not
print for the Salesperson if there are no customers.
Yes the Header section for the Customer data item repeats for every
Salesperson that has customers.
It looped through all of the Salespeople first. Then, it looped through all of
the Customers (stopping at the fifth customer record).
Right before it begins printing the body sections. They only print once.
Right after all the body sections have been printed. They only print once.
With Indentation
It looped through all of the Salespeople first, but for every salesperson
record, it looped through the Customer table (stopping at the fifth customer
record).
Right before it begins printing the body sections. The salesperson header
section only prints once at the top of the first page. The customer Header
section prints right after every salesperson body section.
After all the body sections have been printed. The customer footer section
prints several times during the report right before the next salesperson
body (or footer) section prints. The salesperson footer section prints once
at the very end of the report.
With Linking
It looped through all of the Salespeople first, but for every salesperson
record, it looped through the Customers for that salesperson (if there were
any; stopping at the fifth customer record).
Right before it begins printing the body sections. The salesperson header
section only prints once at the top of the first page. The customer Header
section prints right after every salesperson body section (if the salesperson
has customers).
After all the body sections have been printed. The customer footer section
prints several times during the report right before the next salesperson
body (or footer) section prints. The salesperson footer section prints once
at the very end of the report.
Where did the TransHeader print (it will not be on every page)?
At the top of the second page after the Salesperson Header and Customer
Header.
Basic Reports 4-49
Transfooter
Where did the TransFooter print (it will not be on every page)?
When does a new page get created now (there are two times)?
When the report continues to the next page and when the Salesperson
data item moves to the next record.
JR and PS
Yes. I can click on an empty line and add any other field from the table.
What else does the tab allow you to do to the data item?
Sort it. I can click on the sort button and change the key that the report
uses.
Salesperson
Exercise 4.5.1 How Grouping WorksWhere did the Group Header Section
print?
I forgot to sort the data item with a key that starts contains Posting Date.
Finishing Up
Where did the Header sections print for each data item?
The customer header section printed at the top of the first page. The
customer ledger header section printed right after every customer body
section (for customers that had detail records).
Yes. The subtotals are more than the lines and the grand total is more than
any subtotal.
How did you tell the system that the Amount field on the Group Footer
section should show the total for just that group?
Simply by setting the TotalFields property. The report replaces the value for
the amount field with the value from the sum of the amount fields for the
group.
Exercise 4.6.2 Adding Subtotals and Grand Totals to Indented Data Items
No. The report can only total on one data item at a time.
Stage 1
2 Click Report.
5 Select the first empty line in the Report Designer and enter the
number or name of the Vendor table (23).
6 Select the next empty line in the Report Designer and enter the
number or name of the Vendor Ledger Entry table (25).
7 Indent the Vendor Ledger Entry data item by clicking the right arrow
button at the bottom of the form.
8 With the Vendor Ledger Entry data item still selected, bring up the
properties for that data item.
17 From the Field Menu, add the No., Name, and Phone No. fields.
20 From the Field Menu, add the Posting Date, Document Type,
Document No., Description, and Amount fields.
23 Add the Amount field to the Vendor Ledger Entry footer section.
Delete the label.
24 Line up the Amount field on the footer section with the Amount field
on the body.
26 Save the report with ID of 91700 and the Name Vendor Detail.
Stage 2
7 Add the Amount field to the Vendor Ledger Entry group footer section
and delete the label.
Basic Reports 4-53
8 Line up the Amount field on the footer section with the Amount field
on the body.
Stage 3
Step 4
Are there any records on the report that are outside of that range?
The second data item (Cust. Ledger Entry) does not know about the filter
that the user set.
Are there any records on the report that are outside of that range?
What happens to the report if you leave the Date Filter empty on the
request form?
Exercise 4.7.2 Adding and Taking Away from the Request Form
Customer
They can filter the data item or sort the data item on both tabs.
Customer
They can filter the data item. The sort button no longer appears.
Which two properties determine whether the user sees the tab for a data
item on the request form?
What value does the variable have when the box is checked?
True.
What value does the variable have when the box is not checked?
False.
Check the box and preview the report. Close the preview window and rerun
the report. Is the box still checked?
No.
Check the box and preview the report. Close the preview window and rerun
the report. Is the box still checked?
Yes.
Does the report look the same as the last time you ran the report?
Close the preview window. Rerun the report and make sure the checkbox
is not checked on the Options tab.
The detail information in the Body sections of the Cust. Ledger Entry data
item no longer show up on the report. In fact, that entire section is not
printing. Only the other Cust. Ledger Entry data item sections are printing
along with the Customer sections.
Exercise 4.7.4 Adding a Grand Total with More Than One Data Item
Yes.
4-56 Navision Attain Objects
I could have added a global variable and summed the records myself.
In this section, you will be asked questions about the material covered in
this chapter. Answers to the questions can be found in the subsection
Answers.
Questions
List the names of the three Designers used with reports and describe their
function.
How many times will a Header section print on a report for an indented data
item (assume PrintOnEvery page is turned off and there is data in the
table)? What if the data item is not indented?
What data item property can be used to remove the data items tab on the
request form (assume there are no request filter fields set)?
What two properties of a data item must be set in order to print a sub total
of a field on a group footer section?
What property can be set to start a new page every time a record is read?
What two properties can be used to print a footer at the bottom of every
page?
Given a report that has two data items and the second is indented. What
C/AL code could you write that would most closely resemble this situation?
4-58 Navision Attain Objects
What property can be used to filter an indented data item based on fields in
the unindented data item above it?
Basic Reports 4-59
Answers
False. Some reports do not print anything. They are called processing only
reports.
List the names of the three Designers used with reports and describe their
function.
Request Options Form Designer – design the Options tab of the request
form.
How many times will a Header section print on a report for an indented data
item (assume PrintOnEvery page is turned off and there is data in the
table)? What if the data item is not indented?
Once for every record in the data item that it is indented under.
What data item property can be used to remove the data items tab on the
request form (assume there are no request filter fields set)?
What two properties of a data item must be set in order to print a sub total
of a field on a group footer section?
Whenever the data item’s body sections fill one page and force a new page
to be created. It does not print if another data item causes the new page.
What property can be set to start a new page every time a record is read?
What two properties can be used to print a footer at the bottom of every
page?
4-60 Navision Attain Objects
Given a report that has two data items and the second is indented. What
C/AL code could you write that would most closely resemble this situation?
Nested loops.
While DataItem1.GetRecord Do
While DataItem2.GetRecord Do
;
What property can be used to filter an indented data item based on fields in
the unindented data item above it?
DataitemLink
Chapter 5.
Basic Dataports
Dataport Fundamentals
Designing Dataports
Sample Dataports
Chapter Review
Basic Dataports 5-2
Dataports are objects that are used for importing data from and exporting
data to external text files. During importing and exporting, there is a wide
range of options for defining the format of the external file.
When importing, you can control what happens if a record in the import file
has the same value in the key as an existing record in the database table.
In addition, at dataport field level, you can control whether or not to run the
OnValidate trigger for each field.
Dataport Description
Properties
Triggers
Data Items
Properties
Triggers
Dataport Fields
Properties
Triggers
Request Form
Properties
Triggers
Controls
Properties
Triggers
Dataport Description
Data Item
Dataport Field
Request Form
A request form is a form that is run before the actual dataport begins
execution. It is used to gather requests and options from the user of the
dataport, for example, the name of the external file.
Property
Trigger
Logical Design
Designing a dataport involves two distinct tasks: designing the data model
and defining the layout of the external file.
Basic Dataports 5-4
Data model
You build the data model by designing data items. A data item corresponds
to a table. When exporting data, each data item is iterated for all records in
the underlying table, and you can set up sorting order, keys and table views
to use. For each record, you can decide whether or not it should be written
to the external file.
When importing data, records read from the external file can be inserted in
the table that corresponds to the data item. You can examine the records
before inserting them, and you can specify whether records should be
inserted automatically and whether records already in the database should
be overwritten or updated when a record with the same primary key is read
from the external file (or, of course, whether this record should be inserted
at all).
External file
When the user initiates the dataport run, the OnInitDataport trigger is run.
This trigger can be used to initialize variables, but should not be used for
general processing purposes.
When the OnInitDataport trigger has been executed, the request form for
the dataport is run if it is defined. Here, the user can choose to cancel the
dataport run.
The OnPreDataport trigger can be used to process the user input from the
request form.
When the OnPreDataport trigger has been executed, the external file is
opened, and the processing of the first data item begins.
When the first data item has been processed, the next (if any) data item is
processed in the same way.
When there are no more data items, the OnPostDataport trigger is called.
You can use this trigger to do any post processing that is necessary.
When the OnPostDataport has been processed, the external file is closed.
The transaction that was entered in step 3 ends with an EWT (End Write
Transaction) being issued.
The processing of each data item (steps 5 and 6) is, of course, different for
importing and exporting. The flow charts in Appendix G show the details.
What is important to note in the overall chart is that the entire processing of
a dataport takes place within a transaction. This means that if the
processing is interrupted at any time before the final EWT, there will be no
trace left of the interrupted run afterwards in the database (an external file
will, however, often have been corrupted.)
Note
The Right and Left buttons on the Dataport Designer window can indent
data items in User Portal dataports. For all other kinds of dataports, you
must process one data item (table) at a time.
Basic Dataports 5-7
After you have designed a dataport, you must save and compile it before it
can be run from other objects or from the Object Designer. Normally, you
do this when you have finished designing the dataport. However, you may
want to save a dataport that is not yet finished and thus cannot be
compiled. You can also compile and run a dataport without closing or
saving it.
To save a dataport:
1 When you close a dataport, C/SIDE will ask whether the dataport
should be saved. If it is a new dataport (a dataport that has not been
saved before) you will have to assign it an ID and a name. The ID
must be unique and follow the rules for numbering objects – your
C/SIDE dealer will provide you with this information.
Hint: If you enter ID and Name as dataport properties, these values will
be used, and you will not be prompted for ID and Name when you
close the dataport.
Compiling a Dataport
Dataports, like other objects in C/SIDE, must be compiled before they can
be run. As described above, you can choose to compile a dataport
whenever you save it.
While you are designing a dataport, you may want to test-compile it to find
possible errors. You can test-compile a dataport during design by choosing
the Compile option on the Tools menu.
Running a Dataport
Test-Running Dataports
While designing a dataport, you can test-run it by choosing Run from the
File menu. In this way, the dataport will be compiled and run in its current
stage of development. It will not be saved, which means that you can use
this function to verify that the changes you are making work as intended
before you save them.
Note
You can run a dataport from the list of dataports in the Object Designer by
selecting it and clicking the Run button.
Basic Dataports 5-9
Dataport Properties
This set of properties describes the dataport in general, and this is also
where you specify the format of the external file.
Note that Import and FileName can be set and reset dynamically. For
example, you can create a dataport where the user can select whether to
import or export, or select the name of the external file to read from or write
to (or you can generate a filename automatically once the dataport is run)
Property Meaning
Property Meaning
FileFormat
The FileFormat property determines the format of the external file. This
property defines how a record is read from or written to the file. The
RecordSeparator property defines how the file is broken up into records,
and the FileFormat property then defines how to break each record up into
dataport fields. Finally, the DataItemSeparator property defines how data
items should be separated if the dataport has more than one data item.
Note that data items cannot be nested – although a dataport can have
several data items that are processed sequentially.
Basic Dataports 5-11
FileFormat: Fixed
When the format of the external file is Fixed, the dataport fields in a record
have a fixed width. You can define the starting position and the width of
each dataport field in the record (if the RecordSeparator is a newline
character, you can think of a record as a line of text). The positions and
widths of the dataport fields are properties of the dataport fields (described
in a following subsection).
FileFormat: Variable
When the format of the external file is Variable, the dataport fields in a
record are delimited by characters that you define, and the dataport fields
can have varying widths. The dataport fields are separated by the string
defined as the FieldSeparator property.
This set of properties describes the data items of the dataport, which is the
database table part of the dataport.
Most of these properties are the same and have the same function as the
corresponding properties of a data item in a report (see the Chapter
Designing Reports. Three properties are special for a dataport: AutoSave,
AutoUpdate and AutoReplace.
Property Meaning
Property Meaning
The three Auto* properties determine how records that are read from the
external file are handled. They are also used to resolve the conflict that
arises when a record that has been read from the external file during
importing has the same primary key as a record that already exists in the
database table.
AutoSave and AutoReplace are used to define how records are saved in
the database table.
The following table outlines the effects that the various combinations of
settings for these properties have:
Yes Yes --- The import record will The import record is
update the existing automatically inserted
record in the in the database
database
Suppose you have a table that is an item list. You update the prices by
exporting a list with item numbers (the primary key) and prices to an
external file and then you do some calculations on the prices on a
spreadsheet. Now, when the prices are calculated and you are ready to
import the file with the new prices, it is obvious that the records read from
the external file will have the same primary key as records that are already
in the database. Using AutoSave and AutoReplace will not solve the
problem. If you are replacing every record with the corresponding record
from the import file, all the information except the item numbers and the
prices will be lost (it is assumed that the table contains information other
than the item numbers and the prices, for example names of the items,
stock level, and so forth).
replaces the existing record – but fields that are not present in the imported
record are initialized with the data from the already existing record instead
of being left empty. The existing record is updated with the information that
was revised.
Property Meaning
When fields are exported, the data is converted to text before the export. If
the format is Fixed and the Width is smaller than the actual width of the
data after conversion, the contents will be truncated from the right until it
has the defined Width. That is, a number is not rounded or truncated as a
Basic Dataports 5-15
You will get a warning at design-time if you have defined dataport fields
with starting positions and widths that could cause these dataport fields to
overlap. The error will make it impossible to compile (and thus to execute)
the dataport.
You can, however, have gaps in the dataport fields (the starting position of
the second dataport field does not have to be exactly where the first
dataport field stopped). These gaps may skip unneeded information or
create blank columns in the file.
During importing, a value that is too large for the data type or defined width
of the database table field where it is to be inserted will cause an error and
execution will stop. As the whole dataport is inside a transaction, no traces
will be left of the aborted run in the database.
Basic Dataports 5-16
This section tells you how to create dataports by going through the steps
necessary to create the four fundamental types of dataports: importing and
exporting, each with a fixed and a variable format of the external file.
This sample dataport will export records to a file in fixed format. The
records in the file will be separated by new lines, and within each record
(line, in effect), a dataport field will have the same width in all records, no
matter how wide the actual data of the dataport field is.
The database table that will be used as an example is the G/L Account
table (the Chart Of Accounts). There are several FlowFields among the
dataport fields that are exported, which have to be calculated when
exporting.
Simple Version
The first version is very basic. It will be extended to a more refined object in
the next subsection.
3 C/SIDE opens the Dataport Designer. Select the first DataItem field
and select the G/L Account table from the lookup form that you open
by clicking the Lookup button. The Name is set by default to the name
of the table. You do not have to change it in this dataport.
Basic Dataports 5-17
4 Open the Property Sheet for the dataport (not for the data item). To do
this, click View, Properties while the dataport is selected (you can
select the dataport either by clicking in an empty line in the Dataport
Designer, or by using Edit, Select Object.
7 Click View, Dataport Fields and the Dataport Field Designer opens.
8 In the Dataport Field Designer, click View, Field Menu and the Field
Menu window opens.
9 Select the fields to be exported. Here, the fields No., Name, Balance
at Date and Net Change have been selected. You may have to scroll
the Field Menu window in order to select these fields, depending on
how the Field Menu window is currently sized.
Basic Dataports 5-18
10 Click the Dataport Field Designer to add the fields you have just
selected in the Field Menu window. (You cannot click OK in the Field
Menu window.) You will be asked if you want to append the selected
fields.
11 Click Yes.
Select the CalcFields property, click the AssistButton to open the Field List
window. Then, select those fields from the data item that must be
calculated when they are exported,that is, the FlowFields. In this case, it is
the Balance at Date and Net Change fields. Click OK to close the Field
List window.
Basic Dataports 5-19
Now, you are ready to run the dataport. You can run it before saving it by
clicking File, Run. If you want to save the dataport first, you will be
prompted for a name and a number as with other objects.
When the dataport fields have been inserted from the Field Menu, you can
check the settings of the StartPos and Width properties of all the fields in
the Dataport Field Designer form (accessed by clicking View, Dataport
Fields). They look like this:
As you can see, both StartPos and Width have been filled out for you. They
are assigned values according to these rules:
Date 11
Time 10
Basic Dataports 5-20
Option 10
Decimal 12
Integer 7
Boolean 10
When you run the dataport, you will see the default request form. The first
tab is of little interest, but the second one, Options, is important. Here you
can state the name of the external file to write to.
When you have stated the name of the file, click OK to run the dataport.
The default status window will show you the progress. When the run is
over, you can look at the file in a text editor:
Refined Version
• The first tab in the request form should not be shown, as we do not
want the user to set filters and keys.
You must not set the UseReqForm property to No in order to remove the
request form. Doing this will make it impossible for the user to set the name
of the file that the data should be written to. In fact, since no filename has
been set, the dataport will provoke a runtime error.
Instead, you can select the Options tab and remove the data item tab by
setting a DataItemTableView for the data item. When this property is set –
as opposed to being left undefined – the user cannot change key or sort
order and cannot set a table filter, and the corresponding tab will be
removed by the system.
3 Fill out at least one of the fields. In the preceding picture, Key has
been set to No. and Order has been set to Ascending.
In order to select only some account types you must set a table filter. This
can be done in the DataItemTableView property. Continue from step 3
above:
4 Click the AssistButton in the Table Filter field to open the following
form:
Basic Dataports 5-22
5 Set the values of Field, Type and Value fields as shown in the
preceding picture. This creates a table filter that will select records
where Account Type is Posting or End-Total (the character between
the two values is a | (pipe) which means OR.)
6 Click OK to close the Table Filter form and the Table View form.
FORMAT(ROUND("Balance at Date"/1000,1,'='),0,1)
FORMAT(ROUND("Net Change"/1000,1,'='),0,1)
Basic Dataports 5-23
The file that is created by this dataport could look like the following
imported into a spreadsheet:
This sample dataport will export the same records as the previous
example, but in a variable format. Each dataport field in a record will be
delimited by characters that you define and will only have the width of the
actual data of the dataport field in each of the records.
Very few changes are required to create this dataport instead of the
dataport with fixed width format. You must specify the right set of options
for the data item, as follows:
Basic Dataports 5-24
The exported file could look like the following in a text editor:
Creating a dataport that imports data is not very different from creating one
that exports data. You must, however, take into consideration how the
imported records should be inserted in the database table that lies under
the data item. This is especially relevant if the table already contains
records with the same primary key as some of the records to be imported
will have.
This first example assumes that the table is empty (or that other actions
Basic Dataports 5-25
The file that we are going to import records from, look as follows in an
editor:
In this case, we will import the records into a newly created table. The table
has this layout:
This means that we must decide how the lines in the import file – each line
will become a record in the data item – will be broken down into dataport
fields. The lines have a fixed format, and by carefully looking at the layout
of the lines, these field starting positions displayed in the bottom line can be
deduced:
Basic Dataports 5-26
No. 1 3
Name 4 11
Price 15 6
Once it has been established how the lines in the import file are organized,
creating the dataport is straightforward:
2 Set the Import property to Yes and the FileFormat property to Fixed.
4 Add all the fields from the table to the dataport by using the Dataport
Field Designer and the Field Menu as described earlier. At this point,
the dataport fields will be set up with sizes (and corresponding starting
positions), as deduced from the table design.
Basic Dataports 5-27
5 You must change the setting of StartPos and Width to the values that
are appropriate for the actual file you are going to import data from. In
this example, the values should be set as follows (as described
earlier):
6 The dataport can be run. Remember that if you run it from inside the
Dataport Designer (by clicking File, Run), the records will not be
stored in the database (in order to have them stored, you must run the
dataport from the Object Designer, or call it from a menu.) You may
also want to remove the unnecessary tabs from the request form.
After running the dataport so that records actually are imported into the
database, the table will look like this:
Basic Dataports 5-28
Note that because Field No. is the primary key of the table, the records are
displayed in an order determined by this field – which, incidentally, is not
the same order as they appeared in the import file.
Possible Errors
It is easy to make errors when deciding how to "cut up" the lines in the
import file. In some cases, this will give a runtime error when the dataport is
run. Consider, for example, if we made an error in setting up the Field No.
dataport field so that it had been assigned a width that is one character too
wide. For most of the import file, this would make no difference at all – the
resulting trailing space would be ignored. But the line beginning with
"112Oven..." would provoke a runtime error when C/SIDE read 112O
instead of 112. The "O" (upper case "o") cannot be inserted into an integer
field.
You might consider it fortunate that the error actually provoked a runtime
error. In other cases, the error might not have been detected by C/SIDE, for
example, if the "cut" between two text fields was placed incorrectly. If you
have the opportunity, test your imports carefully before using them for
production.
Hint
In some cases, the order of the fields you want in your table does not
correspond to the order of the dataport fields in the import file. If this is the
case, you can just design the dataport fields to reflect the order that you
need, by adding the fields individually. You will have to set the StartPos
and Width manually.
Basic Dataports 5-29
The data is exactly the same as in the file with fixed format which we
imported from above, but here the dataport fields are separated by
commas. The only differences in creating the dataport are:
The properties of the dataport should look like this when you have finished:
These are the only differences between the fixed format dataport and
variable format dataport. The result of running this dataport will be the
same as running the dataport with a fixed format.
Basic Dataports 5-30
Note
If the order of the dataport fields in the import file is different from the order
of the dataport fields in the data item, you cannot use the same method to
move the dataport fields around as you would if the file had a fixed format.
Instead, you can change the order of the dataport fields in the Dataport
Field Designer.
In this case, you can add the dataport fields in the Dataport Field Designer
in the order in which they appear in the import file:
Note that because the dataport fields have been added one-by-one from
the Field Menu (instead of all-at-once), StartPos and Width have not been
calculated by the designer. It does not matter, however, because these
properties are not used in a dataport with a variable format.
Basic Dataports 5-32
In this section, you are asked questions about the material covered in this
chapter. Answers to the questions can be found in the subsection Answers.
Questions
2 What can you not do with a data item in a dataport that you could do
with a data item in a report?
3 The dataport fields that you create in the Dataport Field Designer must
match what for an import dataport?
5 When must you use the StartPos and Width properties of a dataport
field?
6 True or False. Every dataport field must be bound to a real field in the
data item.
9 When exporting, which dataport file type creates the smallest possible
file?
10 When importing, which dataport properties can you set so that the
user does not see the options tab?
Basic Dataports 5-34
Answers
2 What can you not do with a data item in a dataport that you could do
with a data item in a report?
3 The dataport fields that you create in the Dataport Field Designer must
match what for an import dataport?
Nothing. If AutoSave is set to No, the dataport will not insert or modify
any records automatically.
5 When must you use the StartPos and Width properties of a dataport
field?
6 True or False. Every dataport field must be bound to a real field in the
data item.
Fixed.
9 When exporting, which dataport file type creates the smallest possible
file?
Basic Dataports 5-35
10 When importing, which dataport properties can you set so that the
user does not see the options tab?
Filename property to the name of the file (the user cannot change
it).Import to Yes (the user cannot change it). The options tab
disappears.
Chapter 6.
Basic Codeunits
A C/SIDE Codeunit
Creating Codeunits
Using Codeunits
Chapter Review
6-2 Navision Attain Objects
You may have seen examples of C/AL code in forms and reports. In fact,
C/AL code can be stored in a form, report, or other object. In simple
applications, the normal approach is to place the code in the object that
calls the functions, but as your application grows you will often find that you
use the same functions repeatedly. Instead of declaring the same functions
over and over again, it would be useful if you only had to define them once.
This is where the codeunit becomes useful. Think of a codeunit as a
container for C/AL code that you want to use in many application objects. In
codeunits you can define:
Functions
Global Variables
A global variable is a variable whose scope covers all the functions in the
codeunit.
Temporary Tables
All codeunits include two default triggers called Documentation and OnRun.
In the Documentation section, you can add optional information about the
code such as the purpose of the codeunit, a version number and so on. In
the OnRun section, you can include code that you want the system to
execute when the codeunit is run.
Note
Codeunits contain functions but can also be run. Besides being a container
for functions that can be run individually, a codeunit can itself be run by
writing <CodeunitVariableName>.Run. When you run a codeunit, it is
the code in the OnRun section of the codeunit that will be run.
6-4 Navision Attain Objects
You create a new codeunit or modify an existing codeunit in the same way
you create and modify other application objects, that is, by using the Object
Designer.
To create a codeunit:
3 Click New to create a new codeunit. C/SIDE will open the C/AL editor,
where you can create functions.
3 Click Design and C/SIDE will open the C/AL editor, where you can
modify the codeunit by changing existing functions or adding new
functions.
The C/AL editor is where you view and edit your code. This editor is
designed to make it easy for you to create and modify C/AL code. When
you are in the editor, you have access to the C/AL Symbol Menu that helps
you define C/AL functions. When you use the C/AL Symbol Menu, you can
get help about all C/AL functions. Select the C/AL function name in the
column to the right and press F1.
Basic Codeunits 6-5
When you create a codeunit, the window shows the two default sections
described above (the Documentation and the OnRun section).
From the Object Designer you can open as many codeunits as you like.
Each time you create a new codeunit or open an existing one, it will be
displayed in a separate window. This makes it easy to cut and paste lines
of code between the codeunits.
If you have tried to use other Windows editors, you’ll find the C/AL editor
easy to use. You can access the editing functions both from the Edit menu
and from the toolbar.
Paste
Cut Copy
6-6 Navision Attain Objects
When you work in the C/AL editor, you can use a number of shortcut keys:
To... Press...
When you have created a new codeunit, the next step is to define the
global variables and functions you need in the codeunit. You use the C/AL
Globals tool for this.
1 Make sure that focus is on the C/AL editor. Click View, C/AL Globals
and C/SIDE displays the C/AL Globals window:
2 In the C/AL Globals window, you select whether you want to add a
global variable or a function.
Add a name and a type. If the type you select corresponds to an application
object, you also have to add a subtype, that is, the name of a specific
object in the database. If you select text or code, you have to define a
Basic Codeunits 6-7
length for the variable (the default length is 10 characters for code, and 30
for text). If you select OCX or Automation, you also have to add a subtype.
To add a function:
1 Click the Functions tab in the C/AL Globals window. C/SIDE will
display:
4 For each parameter you have to specify the calling method, a name,
and a data type. You can specify a subtype and a length, but this is
optional.
The calling method can be specified as Var, which means that the
6-8 Navision Attain Objects
5 Click the Return Value tab to define the return value for your new
function.
6 Enter a name for the return value and select a data type from the
drop- down list in the Return Type field. You can also select a length,
but only if the type is text or code.
Basic Codeunits 6-9
8 For each local variable, you must add a name and a type. If the type
you select corresponds to an application object, you also have to add
a subtype, that is, the name of a specific object in the database. If you
select text or code, you have to define a length for the variable (the
default length is 10 characters for code, and 30 for text).
When you write C/AL code in the editor, you can use the C/AL Symbol
Menu to get an overview of:
The information in the C/AL Symbol Menu is divided into columns. The
column to the left shows variable names (if you have defined any) and
function categories. The second column shows the sub-categories, and the
third column (to the right in the picture below) shows the functions in the
category you have selected. You can see the syntax in the bottom of the
window, and you can click OK or Apply to make C/SIDE insert this string in
the C/AL editor.
6-10 Navision Attain Objects
If you need help about any of the C/AL functions shown in the column to
the right, put the focus on the function name and press F1 to activate the
context- sensitive online C/SIDE Reference Guide.
Before the functions in a codeunit can be run, the code has to be compiled
and saved. When you compile the code, the system checks the syntax of
the statements. If the compiler finds any errors in the code it will display a
message.
2 If the system finds any errors in your code it will display a message.
Correct the errors and click Compile again.
Basic Codeunits 6-11
Note
When you use codeunits, you eliminate the need to duplicate code and at
the same time make the code easier to maintain. If you use the same code
repeatedly in your forms or reports, you should create a function in a
codeunit. When you have created a function in a codeunit you can access it
as:
<CodeunitVariableName>.<FunctionName>
Example
F(x:integer)
Begin
...
End
G(x:integer)
Begin
...
End
Any form
(Global variable StatFun declared as codeunit with subtype of
StatisticsFunctions)
...
...
Basic Codeunits 6-13
This method is generally applicable. That is, from any application object
you can access functions in other application objects by prefixing the
function name with the name of the application object containing the
function.
Whenever a codeunit variable is used for the first time, a new instance of
the codeunit is created, that is, a new set of internal variables is initialized
so that different codeunit variables use different sets of internal variables.
Codeunit Assignment
Example
Codeunit 50000 has two functions Set and Get. Set sets an internal
variable to the value of the parameter given. Get returns the value of the
internal variable.
6-14 Navision Attain Objects
VAR
CoMIC1: Codeunit 50000;
CoMIC2: Codeunit 50000;
CoMIC1.Get();
CoMIC2.Get();
//CoMIC1 returns 1; CoMIC2 returns 2
CoMIC2 := CoMIC1;
//CoMIC2 is assigned to CoMIC1 and they now both use
//the same instance
CoMIC1.Get();
CoMIC2.Get();
//both codeunit variables return 1
END;
CLEAR on Codeunits
When you use the function CLEAR on a codeunit variable that has a
reference to a codeunit instance with two or more references, CLEAR only
deletes the reference to the codeunit and not the actual codeunit instance.
In other words, the codeunit stays intact and can still be used by other
codeunit variables that may have been assigned a reference to this
codeunit. To delete a codeunit instance, you must clear all references to
the codeunit with the function CLEAR. If you need to clear the internal
variables in a codeunit, you must call CLEARALL from a user-defined
function within the codeunit. When a local codeunit variable goes out of
scope, meaning that it is no longer used by the codeunit, it is automatically
cleared.
In some cases, the situation requires that only one instance of a codeunit
exist. This means that all codeunit variables of a particular codeunit will use
Basic Codeunits 6-15
the same set of variables. By setting the SingleInstance property for the
codeunit to Yes, all codeunit variables of that codeunit will use the same
instance, thus allowing the developer to create global variables.
Note
It is recommended that you avoid using global variables for most types of
code. However, in certain situations, it may be necessary to use them, for
example, to make sure that you are only using one instance of an external
variable.
A single instance codeunit is instantiated when you use it for the first time.
Normal codeunit instances (codeunits that do not have the SingleInstance
property set) are deleted whenever the last codeunit variable that uses that
codeunit instance goes out of scope. However, single instance codeunits
remain instantiated until you close the company.
Example
Codeunit 50001 has two functions Set and Get. Set sets an internal
variable to the value of the parameter given. Get returns the value of the
internal variable. Codeunit 50001 has the SingleInstance property Set.
VAR
CoSIC1: Codeunit 50001;
CoSIC2: Codeunit 50001;
CoSIC2.Get();
//returns 7 - CoSIC2 uses the same instance as
//CoSIC1, so they use the same internal variables
END;
Note
It is possible to use a single instance codeunit across objects and not only
within the same object.
6-16 Navision Attain Objects
Limitations on Codeunits
All C/AL functions can be used in a codeunit. Notice, however, that you
cannot create a function with the same name as a built-in function. Neither
can two or more user-defined functions have the same name (unless they
are part of different application objects).
In this section, you will be asked questions about the material covered in
this chapter. Answers to the questions can be found in the subsection
Answers.
Questions
7 What function can you use to make a codeunit variable point to a new
instance of a codeunit?
Answers
F5
You must create a variable for the codeunit with the correct subtype.
Yes.
Yes.
Assignment
CU1 := CU2;
7 What function can you use to make a codeunit variable point to a new
instance of a codeunit?
CLEAR(CU1);
No.
6-20 Navision Attain Objects
Appendix A.
Course Test
This appendix gives you a chance to measure what you have learned. It
contains questions from every chapter of the course. You can find the
answers in Appendix B.
QUESTIONS
1 Which of the following objects cannot be created in C/SIDE?
a) Tables
b) Forms
c) Reports
d) Code Groups
a) True
b) False
a) Indexes
b) Table Relations
c) Dataports
d) Keys
II Course Test
a) CharAllowed
b) Length
c) Calcformula
d) Data Type
5 Which property would you use to prevent a user from pasting records
into a table?
a) AllowCutPaste
b) PastIsValid
c) UserPaste
6 Which property would you set to prevent a user from editing a field?
a) Editable
b) Enabled
c) AllowUserEdit
d) AllowModify
7 When you run a table from the Object Designer, what is displayed?
a) Sorting
d) Both a and b.
a) Sorting
d) Both a and b.
10 True or False. The user can only use the primary key on forms.
a) True
b) False
d) Both b and c.
IV Course Test
12 True or False. A conditional table relation can relate its table to more
than one other table.
a) True
b) False
13 What happens when you change the primary key of a record that has
other records in other tables related to it?
d) An error occurs.
b) A ReqFilterField.
c) A SumIndexField.
d) A FlowFilter.
a) A SumIndexField.
b) A FlowFilter.
d) Nothing.
Course Test V
17 What would you name a master table that holds Book Information?
a) Book
b) Books
c) Book Info
d) TblBook
a) Address
b) Addresses
c) Customer Address
d) Customer Addresses
a) A Header table.
b) A Lines table.
a) Entry No.
c) Line No.
a) TableNo
b) TableID
c) SourceTable
d) BoundTable
22 True or False. It is better to start all forms with the form wizard.
a) True
b) False
a) Lookup
b) SourceExpr
c) Drilldown
d) DataField
Course Test VII
24 Card forms…
25 Tabular forms…
a) True
b) False
VIII Course Test
28 What type of button would you usually add to the bottom of a card
form?
a) Command Button
b) Menu Button
c) Option Button
d) You don’t, the wizard adds all the buttons for you.
a) Field Menu
b) C/AL Editor
c) Menu Designer
d) Symbol Menu
30 What control allows you to display one form within another form?
a) Tablebox
b) Textbox
c) Matrixbox
d) SubForm
31 What name would you use for a Tabular form that displays information
from the Book table?
a) Book
b) Books
c) Book Card
d) Book List
Course Test IX
a) F5
b) F9
c) F11
d) Shift+F5
35 What Function key is used to open the Card form from a List form?
a) F5
b) F9
c) F11
d) Shift+F5
X Course Test
36 What Function key is used to open the Statistics form from a Card
form?
a) F5
b) F9
c) F11
d) Shift+F5
a) Sections.
d) Both a and b.
a) PrintOnlyIfDetail
b) AutoUpdate
c) ReqFilterFields
d) CalcFields
a) A data item
b) A control
c) A form
Course Test XI
d) A codeunit
a) Indent them.
b) Link them.
a) TotalFields
b) GroupTotalFields
c) GroupFields
a) TotalFields
b) GroupTotalFields
c) GroupFields
43 To ensure that a tab for a data item is not shown on the request form
you must…
a) True
b) False
a) Financial report
b) Transaction report
c) Document report
d) Posting report
a) Indent them.
b) Link them.
48 If AutoSave is set to No, what property must you set to get the
dataport to update existing records?
a) AutoInsert
b) AutoModify
c) AutoUpdate
d) If AutoSave is set to No, the dataport will not save any records
automatically.
a) onRun
b) onInsert
c) onAfterGetRecord
a) True
b) False
XV Course Test Answers
Appendix B.
ANSWERS
1 Which of the following are not objects that you can create in C/SIDE?
a) Tables
b) Forms
c) Reports
d) Code Groups
a) True
b) False
a) Indexes
b) Table Relations
c) Dataports
d) Keys
Course Test Answers III
a) CharAllowed
b) Length
c) Calcformula
d) Data Type
5 Which property would you use to keep a user from pasting records
into a table?
a) AllowCutPaste
b) PastIsValid
c) UserPaste
6 Which property would you set to keep a field from being edited by the
user?
a) Editable
b) Enabled
c) AllowUserEdit
d) AllowModify
7 When you run a table from the Object Designer, what is displayed?
a) Sorting
d) Both a and b.
a) Sorting
d) Both a and b.
10 True or False. The user can only use the primary key on forms.
a) True
b) False
d) Both b and c.
Course Test Answers V
12 True or False. A conditional table relation can relate its table to more
than one other table.
a) True
b) False
13 What happens when you change the primary key of a record that has
other records in other tables related to it?
d) An error occurs.
b) A ReqFilterField.
c) A SumIndexField.
d) A FlowFilter.
a) A SumIndexField.
b) A FlowFilter.
d) Nothing.
VI Course Test Answers
17 What would you name a master table that holds Book Information?
a) Book
b) Books
c) Book Info
d) tblBook
a) Address
b) Addresses
c) Customer Address
d) Customer Addresses
a) A Header table.
b) A Lines table.
a) Entry No.
c) Line No.
a) TableNo
b) TableID
c) SourceTable
d) BoundTable
22 True or False. It is better to start all forms with the form wizard.
a) True
b) False
a) Lookup
b) SourceExpr
c) Drilldown
d) DataField
VIII Course Test Answers
24 Card forms…
25 Tabular forms…
a) True
b) False
Course Test Answers IX
28 What type of button would you usually add to the bottom of a card
form?
a) Command Button
b) Menu Button
c) Option Button
d) You don’t, the wizard adds all the buttons for you.
a) Field Menu
b) C/AL Editor
c) Menu Designer
d) Symbol Menu
30 What control allows you to display one form within another form?
a) Tablebox
b) Textbox
c) Matrixbox
d) SubForm
31 What name would you use for a Tabular form that displays information
from the Book table?
a) Book
b) Books
c) Book Card
d) Book List
X Course Test Answers
a) F5
b) F9
c) F11
d) Shift+F5
35 What Function key is used to open the Card form from a List form?
a) F5
b) F9
c) F11
d) Shift+F5
Course Test Answers XI
36 What Function key is used to open the Statistics form from a Card
form?
a) F5
b) F9
c) F11
d) Shift+F5
a) Sections
d) Both a and b
a) PrintOnlyIfDetail
b) AutoUpdate
c) ReqFilterFields
d) CalcFields
a) A data item
b) A control
c) A form
XII Course Test Answers
d) A codeunit
a) Indent them
b) Link them
a) TotalFields
b) GroupTotalFields
c) GroupFields
a) TotalFields
b) GroupTotalFields
c) GroupFields
43 To cause a tab for a data item not to show on the request form you
must…
a) True
b) False
a) Financial report
b) Transaction report
c) Document report
d) Posting report
a) Indent them
b) Link them
48 If AutoSave is set to No, what property must you set to get the
dataport to update existing records?
a) AutoInsert
b) AutoModify
c) AutoUpdate
d) If AutoSave is set to No, the dataport will not save any records
automatically.
a) onRun
b) onInsert
c) onAfterGetRecord
50 True or False. You can assign one codeunit variable the instance of
another codeunit variable.
a) True
b) False