Question 220
A Dynamics 365 Business Central development project faces this issue: A developer compares two Option values using magic integers scattered through AL code. Which action best addresses the requirement?
Explanation
Correct Answer
Replace fragile numeric assumptions with appropriate named enum values and explicit comparisons where supported. is the best response because named values make state transitions easier to understand and less error-prone during extension evolution. The proposed outcome is checked by: Unit tests verify each named state without relying on accidental numeric ordering.
Incorrect Answers
That change would address a different situation: A partner uses a long text field for fixed domain codes and repeated typos create unhandled cases. Here the key constraint is that named values make state transitions easier to understand and less error-prone during extension evolution. The intended verification is Unit tests verify each named state without relying on accidental numeric ordering.
The related but distinct situation is “A large AL procedure mixes tax lookup, user interaction, and data writes in nested conditionals”. Cohesive procedures reduce branching complexity and simplify validation and debugging. For the stated problem, “Replace fragile numeric assumptions with appropriate named enum values and explicit comparisons where supported” addresses the central condition.
This alternative addresses the separate case “A helper procedure modifies a purchase line silently without running its standard validation”. Direct assignment can bypass field validation logic and allow inconsistent dependent values. The deciding requirement here is “Replace fragile numeric assumptions with appropriate named enum values and explicit comparisons where supported”.