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>()

FunctionDescription
calcfieldsCalculate FlowFields
calcsumsCalculate Sift Sums
changecompanyChange Company for the record
getGet(primary key fields)
locktableLock the table
resetReset (remove all filters)
isemptyTest if there are no records with the current filters
initInitialize an empty record
insertInsert the current record
modifyModify the current record
deleteDelete the current record
deleteallDelete all records within the current filters
validateValidate a field (simulating the field being typed in)
setfilterSet a filter on a field
setrangeSet a range filter on a field
getfilterGet the filter from a field as a text
findsetFind a set of records
findfirstFind the first record
findlastFind the last record
findFind with operator
nextAdvance the record pointer inside a recordset
countReturns the record count
countapproxReturns an approximated record count (faster)
testfieldTest a field for a specific value
modifyallModify all records

Supported built-in functions

(lookup Microsoft documentation for details on docs.microsoft.com)

commitCommit a transaction
createdatetimeCreate a DateTime value from a Date and Time
currentdatetimeReturn current date and time as a DateTime value
dmy2dateCreate a Date value from Day, Month and Year
date2dmySplits a Date value into day, month year.
date2dwySplits a Date value in to date, week, year
todayReturn current date
workdateReturn current WorkDate
timeReturn current time
randomReturns a random integer
randomizeDefines the randomization seed
formatFormat a value as a Text value
calcdateCalculate a date from a date formula
clearNot initializing record fields with InitValue(!)
powerMath power function
absMath abs function
roundRound a decimal a specific fraction
strlenReturns length of a Text value
strposReturns the position of a subtext inside a Text
copystrCopy a substring from a Text
delstrDelete a substring in a Text
errorHalt execution, roll back the current transaction and show an error
strmenuOpens a menu when the user can select between different options
confirmAsk the user a yes/no question
messageOutput a text to the console (or show a message dialog)
page.runRun a page
page.runmodalRun a page and wait
report.runRun a report
codeunit.runRun a codeunit
exsetSets a value in an Excel sheet (ToolBox only)
exgetGets a value from an Excel sheet (ToolBox only)
evalRun code in string parameter (ToolBox only)

Supported Date Types

Date Type
Integer
Decimal
Text
Code
Date
Time
DateTime
Boolean
Record
Option

Known Issues

IssueDetails
not is not supported in boolean expressionUse = false or = true instead.