BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: TryGetDictionaryValueFromKey should not be a try function

Open DrieVeertien opened this issue 5 months ago • 5 comments

Describe the issue

In page 9082 "Customer Statistics FactBox" there is a LOCAL function:

[TryFunction] local procedure TryGetDictionaryValueFromKey(var DictionaryToLookIn: Dictionary of [Text, Text]; KeyToSearchFor: Text; var ReturnValue: Text) begin ReturnValue := DictionaryToLookIn.Get(KeyToSearchFor); end;

And only gets used in the trigger:

trigger OnPageBackgroundTaskCompleted(TaskId: Integer; Results: Dictionary of [Text, Text]) var CalculateCustomerStats: Codeunit "Calculate Customer Stats."; DictionaryValue: Text; begin if (TaskId = TaskIdCalculateCue) then begin if Results.Count() = 0 then exit;

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetLastPaymentDateLabel(), DictionaryValue) then
            Evaluate(LastPaymentDate, DictionaryValue);

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetTotalAmountLCYLabel(), DictionaryValue) then
            Evaluate(TotalAmountLCY, DictionaryValue);

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetOverdueBalanceLabel(), DictionaryValue) then
            Evaluate(OverdueBalance, DictionaryValue);

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetSalesLCYLabel(), DictionaryValue) then
            Evaluate(SalesLCY, DictionaryValue);

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetInvoicedPrepmtAmountLCYLabel(), DictionaryValue) then
            Evaluate(InvoicedPrepmtAmountLCY, DictionaryValue);

        if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetLinkedVendorNoLabel(), DictionaryValue) then
            LinkedVendorNo := CopyStr(DictionaryValue, 1, MaxStrLen(LinkedVendorNo));
        BalanceAsVendorEnabled := LinkedVendorNo <> '';
        if BalanceAsVendorEnabled then
            if TryGetDictionaryValueFromKey(Results, CalculateCustomerStats.GetBalanceAsVendorLabel(), DictionaryValue) then
                Evaluate(BalanceAsVendor, DictionaryValue);
    end;
end;

This is extremely annoying when starting a debug session and opening a page where this factbox is shown. Next to the fact this is a weird way to retrieve a value from a dictionary. I suggest using the if contains functionality. As I will describe in the expected behavior.

Expected behavior

Remove the Try function tag and make changes to procedure like this:

local procedure TryGetDictionaryValueFromKey(var DictionaryToLookIn: Dictionary of [Text, Text]; KeyToSearchFor: Text; var ReturnValue: Text): Boolean begin if not DictionaryToLookIn.ContainsKey(KeyToSearchFor) then exit(false); ReturnValue := DictionaryToLookIn.Get(KeyToSearchFor); exit(true); end;

Steps to reproduce

Start debug session without any breakpoints but with "breakOnError":true, in the launch.json

Additional context

No response

I will provide a fix for a bug

  • [x] I will provide a fix for a bug

DrieVeertien avatar Jun 26 '26 12:06 DrieVeertien

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

JesperSchulz avatar Jun 26 '26 12:06 JesperSchulz

I agree with this one, it's very frustrating... The Dictionary.ContainsKey() function exists, so why not use it? 😄

vgs-7 avatar Jun 26 '26 12:06 vgs-7

Coverage: issue-only analysis of microsoft/BCApps#8840; no code change reviewed; no implementation or fix proposed; repository evidence searched: customer-statistics objects, W1 and localized tests, source history, materialized country callers, first-party app consumers and dependencies, disabled tests, and build definitions at BCApps revision ae337e48e2; not covered: affected build, exact debugger error and customer data, runtime reproduction, compilation, test execution, live DME availability, internal triage report, and ADO history.

BC impact analysis

Affected areas

  • Sales and Finance/GL: customer statistics and optional payment information.
  • Service, Jobs, and Reservations: additional hosts of the same FactBox; no transaction-processing failure established.
  • Affected implementation: page 9082 "Customer Statistics FactBox", with codeunit 9082 "Calculate Customer Stats." and codeunit 1302 "Customer Mgt." supplying results.

Reported severity and reproducibility: Developer debugging interruption; partial reproduction details. The issue specifies breakOnError: true, but omits the affected build, host page, exact error, and customer data. Source evidence supports a missing-key lookup when a customer has no unreversed payment. No runtime reproduction or tests were performed.

Customer-facing behavior: Opening a page with this FactBox can interrupt an active debugging session at a caught lookup error. Uninterrupted routine debugging is implied by the complaint; separate acceptance criteria are not stated. No normal, non-debug customer failure is established.

Documented debugger behavior: Microsoft documents that break-on-error includes handled errors. The launch settings map true to All and distinguish ExcludeTry. The reported stop is therefore consistent with the selected debugger setting.

Existing tests

  • ERM Customer Statistics.CustomerStatisticsFactboxLastPaymentDate (codeunit 134389): posts three payments, reverses the latest, and checks the remaining payment date. Does not detect the reported debugger behavior.
  • ERM Customer Statistics.CustomerStatisticsFactboxDrillDownLastPaymentDate (codeunit 134389): checks ledger drilldown after the same reversal setup. Does not detect the reported debugger behavior.
  • ERM Sales Document.CustomerStatisticsYearToDate (codeunit 134385; W1, BE, CZ, NA): posts journal entries and checks displayed sales and caption. No debugger-stop assertion.
  • Test codeunits identified: codeunit 134389 "ERM Customer Statistics"; codeunit 134385 "ERM Sales Document".
  • Coverage is partial; no exact detecting test was identified. The inspected codeunits disable test permissions. These methods were not found in the searched disabled-test definitions, but the build project Tests-ERM-Sales marks NA unsupported.

Affected E2E scenarios

  • Customer statistics during debugging: page opening, background completion, and display when payment information is absent.
  • Payment reversal and statistics review: statistics after payments are reversed, including the uncovered all-payments-reversed case.
  • App-hosted customer statistics during debugging: customer-linked Shopify orders, subscription contracts, and extended customer pages.

Existing tests for affected E2E scenarios

  • Customer statistics during debugging: ERM Sales Document.CustomerStatisticsYearToDate (codeunit 134385; W1, BE, CZ, NA) - journal posting and statistics display; Partial coverage; detects exact behavior: No.
  • Payment reversal and statistics review: ERM Customer Statistics.CustomerStatisticsFactboxLastPaymentDate and ERM Customer Statistics.CustomerStatisticsFactboxDrillDownLastPaymentDate (both codeunit 134389) - payment posting, one reversal, date selection, and drilldown; Partial coverage; detects exact behavior: No.
  • App-hosted customer statistics during debugging: None identified.
  • E2E test codeunits identified: codeunit 134389 "ERM Customer Statistics"; codeunit 134385 "ERM Sales Document".

Coverage needed once a fix lands: Agreed debugger behavior with absent payment information; present/absent statistics and customer switching; all-payments-reversed behavior; least-privilege statistics access; identified hosted FactBoxes.

Localizations impacted: APAC; BE; CH; CZ; ES; FR; GB; IT; NA; NL; NO; RU. These have direct consumers of the shared FactBox; source exposure does not mean a runtime incident was reproduced in each market.

Potentially impacted localizations: IN - GST Sales archive FactBoxes default to hidden.

First-party apps impacted: Advance Payments Localization for Czech; Basic Experience; Shopify Connector; Subscription Billing.

Potentially impacted first-party apps: GST Sales (direct hidden hosts); GST Application, GST on Payments, Shopify Connector BE, Shopify Connector NA (dependency-only); GST Return and Settlement (transitive).

First-party app coverage: No exact statistics/debugger test was identified in the searched app test sources. Direct-consumer verification is required for Advance Payments Localization for Czech, Basic Experience, GST Sales, Shopify Connector, and Subscription Billing.

Regression origin: Pre-existing / legacy codebase; Medium confidence. Earliest traceable import 43e6e5a2b6 (November 12, 2025) already contains the relevant behavior. Blame at synchronization commit 748fdaa43f (June 29, 2026) postdates the June 26 issue report and is not an introducing-change candidate. No duplicate or matching prior fix was found in searched local/GitHub history; ADO and internal triage were not assessed.

Potential regression risk of a fix: Shared FactBox statistics, optional payment information, and payment/reversal/drilldown expectations require cross-consumer verification.

Recommendation: Recommend: Needs more information - The source supports the interruption, but stopping on caught errors is documented for the selected debugger setting. A human decision is needed on the expected debugging experience for routine optional-data handling. The affected build, exact error, customer prerequisites, and separate acceptance criteria are missing. No duplicate or prior fix was found in searched history. Overall confidence: Medium.

Suggested test buckets to run in DME

  • Buckets: RunALTests_BE_Bucket3; RunALTests_CZ_Bucket3; RunALTests_NA_Bucket3; RunALTests_W1_Bucket2; RunALTests_W1_Bucket3.
  • Unmapped / needs manual bucket assignment: none.
  • Names are resolved from the September 15, 2026 snapshot, including all matching numeric-range mappings. Live task availability was not checked; the NA project exclusion noted above must not be mistaken for runnable coverage.

A full regression and impact analysis was generated by scm-impact-agent.

PredragMaricic avatar Oct 13 '26 15:10 PredragMaricic

Hi @DrieVeertien, thanks again for offering to contribute! This issue is approved, so you’re welcome to open a PR with your fix. As you selected “I will provide a fix for a bug,” the next step is for you to provide the implementation.

Are you still planning to create a PR? If anything is blocking you, or your plans have changed, please let us know.

JesperSchulz avatar Nov 03 '26 14:11 JesperSchulz

I am, I will do this right this moment :) @JesperSchulz

DrieVeertien avatar Nov 03 '26 15:11 DrieVeertien