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

No way to differentiate between RecordRef.Copy when using Variant #7732

Closed
navdotnetreqs opened this issue Apr 28, 2024 · 3 comments
Closed

Comments

@navdotnetreqs
Copy link

When using a variant for generic code, there doesn't seem to be a way to differentiate between overloaded RecordRef.Copy()-function calls.

If the variant was a recordref, I could do

sourcerecref:=variant;
recordref.copy(sourcerecref);

But in this case the variant is a Record, which is precisely why I need recref.copy.

"The call is ambiguous between the method 'Copy(var Table, [Boolean])' defined in Class 'RecordRef' by the extension '' and the method 'Copy(RecordRef, [Boolean])' defined in Class 'RecordRef' by the extension ''.AL[AL0196]"

A type "Table" does not exist and we cannot do a cast, so this can probably not be done unless the Copy-function is split into two..?

@BazookaMusic
Copy link

This probably requires a new overload for the copy function to handle the record. There's no generic record type to cast to

@ernestasjuska
Copy link

ernestasjuska commented Jun 7, 2024

Hi, I think what you are looking for is this:

var
     MyTable: Record "My Table";
     MyTableRecordRef: RecordRef;

MyTableRecordRef.GetTable(MyTable);

GetTable is equivalent to Copy.

This works with both normal records and temporary records (table gets shared). Expand to see the code.
table 50100 "My Table"
{
    fields
    {
        field(1; K; Integer)
        {
        }
    }
}

report 50100 "Test My Table"
{
    UsageCategory = Tasks;
    ApplicationArea = All;
    ProcessingOnly = true;

    trigger OnPreReport()
    var
        MyTable: Record "My Table";
        TempMyTable: Record "My Table" temporary;
    begin
        GlobalLanguage(1033);

        MyTable.Reset();
        MyTable.DeleteAll(true);

        MyTable.Init();
        MyTable.K := 1;
        MyTable.Insert(true);

        MyTable.Init();
        MyTable.K := 2;
        MyTable.Insert(true);
        MyTable.Mark(true);

        MyTable.Init();
        MyTable.K := 3;
        MyTable.Insert(true);
        MyTable.Mark(true);

        MyTable.SetFilter(K, '>%1', 0);
        MyTable.MarkedOnly(true);


        TempMyTable.Init();
        TempMyTable.K := -1;
        TempMyTable.Insert(true);

        TempMyTable.Init();
        TempMyTable.K := -2;
        TempMyTable.Insert(true);
        TempMyTable.Mark(true);

        TempMyTable.Init();
        TempMyTable.K := -3;
        TempMyTable.Insert(true);
        TempMyTable.Mark(true);

        TempMyTable.Init();
        TempMyTable.K := -4;
        TempMyTable.Insert(true);
        TempMyTable.Mark(true);

        TempMyTable.SetFilter(K, '<%1', 0);
        TempMyTable.MarkedOnly(true);

        Message(
            'Normal: %1\\Temporary: %2',
            GetRecordInfo(MyTable),
            GetRecordInfo(TempMyTable));
    end;

    local procedure GetRecordInfo(
        RecordVariant: Variant): Text
    var
        _RecordRef: RecordRef;
    begin
        _RecordRef.GetTable(RecordVariant);
        exit(StrSubstNo(
            'IsTemporary: %1; Count: %2; Filters: %3',
            _RecordRef.IsTemporary,
            _RecordRef.Count,
            _RecordRef.GetFilters()));
    end;
}

Output:

Normal: IsTemporary: No; Count: 2; Filters: Marked: Yes, K: >0

Temporary: IsTemporary: Yes; Count: 3; Filters: Marked: Yes, K: <0

@thloke
Copy link
Contributor

thloke commented Sep 10, 2024

Thanks for the suggestion. Since this is an improvement and not a bug, you can post this to our Ideas forum at https://aka.ms/BusinessCentralideas, or vote up the idea if its already there. We're constantly monitoring top Ideas and will consider them for a future release.

@thloke thloke closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants