Edit

Share via


Setting conditional breakpoints

As part of debugging code, you can set breakpoints and for a certain breakpoint, you can define a condition. If the condition evaluates as true, then code execution breaks at the breakpoint. If the condition is false, then code execution continues. The condition can include any variables or fields that are currently in scope. You can compare a variable or a field to another variable or field, or you can compare a variable or field to a literal value. If you compare to a literal value, then the variable or field that you use in the breakpoint condition must be of one of the following data types:

Simple data types supported

  • BigInteger
  • Boolean
  • Code
  • Decimal
  • Integer
  • Option
  • Enum
  • Text

Complex data types supported (version 26 and later)

  • Array
  • List
  • Dictionary
  • Record/RecordRef fields
  • Variant (when it wraps one of the above)

Operators supported

Operator Description Remarks
= Equal to -
<> Not equal to -
< Less than -
> Greater than -
<= Less than or equal to -
=> Greater than or equal to -
- Numeric negation Supported from version 26 and later.
NOT Logical negation Supported from version 26 and later.
AND OR Logical Use parentheses to control precedence.

Supported from version 26 and later.

Note

Parenthesize complex expressions explicitly; AL operator precedence rules apply.

To set a conditional breakpoint

When you've enabled debugging mode, and found a place in the code where you want to test a condition, you can right-click the margin of the code editor, and then choose Add Conditional Breakpoint. Or, you can right-click on an existing breakpoint and choose Edit Breakpoint. In the inline dialog, choose Expression and then enter a condition that you want to test.

Note

There are other options in the inline dialog, such as Hit Count and Log Message. These options aren't supported in AL.

Note

If you clear an existing condition, then that breakpoint is no longer a conditional breakpoint.

Examples

In this example, you want to set a breakpoint to debug an application process that loops over a collection of invoices, and stops responding on a particular invoice, for example, on sales invoice no. 103007. To just break for that invoice, you can set a breakpoint on the first line of code in the loop, and set the following condition on the breakpoint.

SalesInvoiceHeader."No." = '103007'  

When the code execution reaches the breakpoint, the condition is evaluated. If the condition is true, then the code execution breaks at the breakpoint. If the condition is false, then the code execution continues.

Here are some additional examples of conditional breakpoints:

Break when a dictionary entry equals a value:

CustomerAges['ALFRED'] > 30

Break when the third element in an array is negative:

MyArray[3] < 0

Break on combined criteria (parenthesized):

(SalesHeader.Status = SalesHeader.Status::Open) AND (SalesHeader."No." = '103007')

Break when a Boolean flag is false:

NOT IsValidated

Get started with AL
Debugging in AL