[Bug]: TryGetDictionaryValueFromKey should not be a try function
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- developer-experience
Research direction
Start at page 9082, "Customer Statistics FactBox," and inspect TryGetDictionaryValueFromKey and its calls in OnPageBackgroundTaskCompleted. Review launch.json with breakOnError enabled, then verify that missing dictionary keys no longer trigger the debugger while the expected values are still evaluated and assigned.
Written by the indexing model from the issue text.
Description
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
- I will provide a fix for a bug
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 621
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/BCApps
-
Team: Finance
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Approved event-request ext-ready-to-implement Team: Finance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Approved event-request ext-ready-to-implement Team: SCM
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
event-request Team: SCM
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Team: SCM
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
All issues in microsoft/BCApps
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hemilabs/ui-monorepo#2332 ·
-
Help-Wanted Needs-Triage Package-Update
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/winget-pkgs#438662 ·
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·