AL icon indicating copy to clipboard operation
AL copied to clipboard

Variant can't contain a Records Company information

Open thellMa opened this issue 1 year ago • 3 comments

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.

thellMa avatar Dec 12 '24 17:12 thellMa

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.

BazookaMusic avatar Dec 12 '24 17:12 BazookaMusic

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 avatar Dec 12 '24 19:12 thellMa

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?

thellMa avatar Dec 13 '24 07:12 thellMa