Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC2021w1. Return record from table procedure #6529

Closed
DmitryKatson opened this issue Mar 15, 2021 · 5 comments
Closed

BC2021w1. Return record from table procedure #6529

DmitryKatson opened this issue Mar 15, 2021 · 5 comments

Comments

@DmitryKatson
Copy link

Describe the bug
When i create a procedure on the table or tableextension and return the record this doesn't work

To Reproduce

this returns empty record
tableextension 50100 "PurchaseLineExt" extends "Purchase Line" { procedure FindFirstRec(): Record "Purchase Line" begin Rec.FindFirst(); end; }

this returns first record
tableextension 50100 "PurchaseLineExt" extends "Purchase Line" { procedure FindFirstRec() PurchLine: Record "Purchase Line" begin PurchLine.FindFirst(); end; }

Expected behavior
Should return Rec

Screenshots

5. Versions:

  • AL Language:
    7.0.426055
  • Business Central:
@IamLerxx
Copy link

Please clarify.
tableextension 50100 "PurchaseLineExt" extends "Purchase Line" { procedure FindFirstRec(): Record "Purchase Line" begin Rec.FindFirst(); end; }

": Record "Purchase Line"" just says, that the return type of the function is a Record of Type Purchase Line.
This return type has no connection to the Rec.
To get the desired functionality add a "exit(Rec);" after the FindFirst.
tableextension 50100 "PurchaseLineExt" extends "Purchase Line" { procedure FindFirstRec(): Record "Purchase Line" begin Rec.FindFirst(); exit(Rec); end; }

@dzzzb
Copy link

dzzzb commented Mar 15, 2021

Do you mean the first one? Why should it return Rec?? Rec means the global current record, not the result of the function. You did not name the result so as to assign to it, nor did you assign to it with exit(), so of course it's still default initialised. It's not related to Rec.

@dzzzb
Copy link

dzzzb commented Mar 15, 2021

To get the desired functionality add a "exit(Rec);" after the FindFirst.

Sure, but then doing that is pointless, since the Rec.FindFirst() already changed the state of the instance on which the method was called, so they can just use that, instead of also copying it to the result.

@IamLerxx
Copy link

To get the desired functionality add a "exit(Rec);" after the FindFirst.

Sure, but then doing that is pointless, since the Rec.FindFirst() already changed the state of the instance on which the method was called, so they can just use that, instead of also copying it to the result.

In case of TableExtensions you are right.

In case of PageExtensions returning the Rec would be good as it would make the difference between:
myPage.FindFirstRec();
myPage.GetRecord(myRec);
and
MyRec := MyPage.FindFirstRec();

Also in the example provided by dkatson the return type of the function is set, so it should return something.

@qutreson
Copy link
Contributor

I am closing this issue as this is the expected behavior. The other comments on the issue provide more information on how to handle this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants