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

Variant can't contain a Records Company information #7933

Open
thellMa opened this issue Dec 12, 2024 · 3 comments
Open

Variant can't contain a Records Company information #7933

thellMa opened this issue Dec 12, 2024 · 3 comments

Comments

@thellMa
Copy link

thellMa commented Dec 12, 2024

Got issues with recordref with other companies in BC together with variants. How can I get this fixed ?

Working with a lot of RecordRef's and variants. Found out today that RecordRef do have CurrentCompany, but it doesn't work if the assignment to RecordRef comes from an variant and not the record itself.

Example code;

trigger OnOpenPage()

var

    customer: Record Customer;

    recordref: RecordRef;

    variant: Variant;

begin

    customer.ChangeCompany('OTHER COMP');

    recordref.GetTable(customer);

    Message(recordref.CurrentCompany);

 

    clear(recordref);

    variant := customer;

    recordref.GetTable(variant);

    Message(recordref.CurrentCompany);

end;

First message is correct company (OTHER COMP). second message will be current company and not OTHER COMP.

@BazookaMusic
Copy link
Contributor

It's not a bug. Assigning to variants happens by value, similar to passing the record to a function. State like filters and company is lost this way. So the record in the variant should have the current company.

I would suggest passing the company as a parameter or variable wherever you need it. Otherwise you can also pass a record ref.

@thellMa
Copy link
Author

thellMa commented Dec 12, 2024

Not really true, filters will get transferred also, but it makes sense that it will be a copy by value.

Can this however be added if it is not by design? As recordref.currentcompany do exists, and I dont like to create recordref every time I want to send an record to a generic function to do some handling. Similar like Microsoft have done with tempblob.FromRecord function.

@thellMa
Copy link
Author

thellMa commented Dec 13, 2024

Investigated this little more, if passing the record first to an recordref and then to an variant everything works fine also.

    trigger OnOpenPage()
    var

        customer: Record Customer;
        recordref, recordref2 : RecordRef;
        variant: Variant;
    begin


        customer.ChangeCompany('OTHER COMP);
        customer.SetRange("No.", '10000', '10010');

        recordref.GetTable(customer);
        Message('%1 - %2', recordref.CurrentCompany, recordref.GetFilters);


        // clear(recordref);
        variant := recordref;
        recordref2.GetTable(variant);
        Message('%1 - %2', recordref2.CurrentCompany, recordref2.GetFilters);

    end;

the two messages will be the same here.
From my point I think that when the framework is copying the record (by value) to an variant it is just missing which company the record did belong to. As it just works fine with the recordref's.
Perhaps I am missing something here?

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

2 participants