Unlocking Flexibility: Exploring Advanced Lookup Techniques in Dynamics NAV/BC

Unlocking Flexibility: Exploring Advanced Lookup Techniques in Dynamics NAV/BC

Instead of writing many lines of code, we can use Page.RunModal(0, Rec) to get a record from the table depending on the source type. For instance, we can apply a filter to a RecordRef or the actual Record according to the Source type and then send that filtered record to a Variant. Alternatively, if no filter is necessary, we can directly open the RecordRef or send an unfiltered Record to the Variant.


field(SourceType; SourceType)
                    {
                        Caption = 'Source Type';
                        ShowMandatory = true;
                        ToolTip = 'Specifies the value of the From Source Type field.';
                        trigger OnValidate()
                        begin
                            Clear(FromDocNo);
                        end;
                    }
 
field(FromDocNo; FromDocNo)
                    {
                        Caption = 'No.';
                        Editable = false;
                        ShowMandatory = true;
                        ToolTip = 'Specifies the value of the From No. field.';
                        trigger OnDrillDown()
                        begin
                            FromDocNo := SelectRecord(SourceType);
                        end;
                    }

local procedure SelectRecord(SourceTypeP: Enum "Gen. Journal Source Type"): Code[20]
    var
        RecVar: Variant;
        RecRef: RecordRef;
    begin
        case SourceType of
            SourceType::"Bank Account":
                begin
                    RecRef.Open(Database::"Bank Account");
                    RecRef.Field(1).SetRange(SourceTypeP.AsInteger());
                end;
            SourceType::Customer:
                RecRef.Open(Database::"Customer");
            SourceType::Vendor:
                RecRef.Open(Database::Vendor);
            SourceType::Employee:
                RecRef.Open(Database::Employee);
        end;

        RecVar := RecRef;
        if Page.RunModal(0, RecVar) <> Action::LookupOK then
            exit;

        RecRef.GetTable(RecVar);
        exit(RecRef.Field(1).Value);
    end;

var
        FromDocNo: Code[20];
        SourceType: Enum "Gen. Journal Source Type";
        SourceName: text[50];
        

要查看或添加评论,请登录

Senthil Kumar Varatharajan的更多文章

社区洞察

其他会员也浏览了