A ToolBox program is a single file with global variables, procedures and the main begin end; section for starting the program. The grandfather of AL is Pascal, and the base structure of a ToolBox program is very similar to a classic Pascal program.
AL in the ToolBox is a subset of real AL, there are many things you can do in the ToolBox, but it’s only a fraction of what you can do with the AL language in Visual Studio Code.
The shortest possible ToolBox program looks like this:
begin message('Hello World'); end;
Actually, it can be made even shorter, you can omit the begin end; and just do:
message('Hello World');
The following snippet is a skeleton example of a script with globals variables, procedures and a main section:
// Start by declaring global variables var varname: vartype; // You can declare procedures procedure proc() var procvar : vartype; begin // Stuff that happens inside proc() end; procedure procwithreturn() : returnvartype begin exit(returnvalue); end; // Main program entry, // this is the first code that executes, // defined by the begin begin // Here is your start code message('Hello world'); end;
Statements
ToolBox AL supports the following statements:
begin <statements> end; |
for <incrementor> := <start> to <end statement> do |
repeat <statements> until <bool expression>; |
if <expression> then <statement> [else <statement>] |
while <expression> do <statement> |
case <expression> of <expression>: <statement> <expression>: <statement> [else <statements>] end; |
break; |
exit(<returnvalue>); |
<variable> := <expression>; |
Supported Record.<Function>()
Function | Description |
---|---|
calcfields | Calculate FlowFields |
calcsums | Calculate Sift Sums |
changecompany | Change Company for the record |
get | Get(primary key fields) |
locktable | Lock the table |
reset | Reset (remove all filters) |
isempty | Test if there are no records with the current filters |
init | Initialize an empty record |
insert | Insert the current record |
modify | Modify the current record |
delete | Delete the current record |
deleteall | Delete all records within the current filters |
validate | Validate a field (simulating the field being typed in) |
setfilter | Set a filter on a field |
setrange | Set a range filter on a field |
getfilter | Get the filter from a field as a text |
findset | Find a set of records |
findfirst | Find the first record |
findlast | Find the last record |
find | Find with operator |
next | Advance the record pointer inside a recordset |
count | Returns the record count |
countapprox | Returns an approximated record count (faster) |
testfield | Test a field for a specific value |
modifyall | Modify all records |
Supported built-in functions
(lookup Microsoft documentation for details on docs.microsoft.com)
commit | Commit a transaction |
createdatetime | Create a DateTime value from a Date and Time |
currentdatetime | Return current date and time as a DateTime value |
dmy2date | Create a Date value from Day, Month and Year |
date2dmy | Splits a Date value into day, month year. |
date2dwy | Splits a Date value in to date, week, year |
today | Return current date |
workdate | Return current WorkDate |
time | Return current time |
random | Returns a random integer |
randomize | Defines the randomization seed |
format | Format a value as a Text value |
calcdate | Calculate a date from a date formula |
clear | Not initializing record fields with InitValue(!) |
power | Math power function |
abs | Math abs function |
round | Round a decimal a specific fraction |
strlen | Returns length of a Text value |
strpos | Returns the position of a subtext inside a Text |
copystr | Copy a substring from a Text |
delstr | Delete a substring in a Text |
error | Halt execution, roll back the current transaction and show an error |
strmenu | Opens a menu when the user can select between different options |
confirm | Ask the user a yes/no question |
message | Output a text to the console (or show a message dialog) |
page.run | Run a page |
page.runmodal | Run a page and wait |
report.run | Run a report |
codeunit.run | Run a codeunit |
exset | Sets a value in an Excel sheet (ToolBox only) |
exget | Gets a value from an Excel sheet (ToolBox only) |
eval | Run code in string parameter (ToolBox only) |
Supported Date Types
Date Type |
---|
Integer |
Decimal |
Text |
Code |
Date |
Time |
DateTime |
Boolean |
Record |
Option |
Known Issues
Issue | Details |
---|---|
not is not supported in boolean expression | Use = false or = true instead. |