Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

GetSelectionFilter + SelectionFilterManagement issue

Posted on by

hi,
I have an AL message that shows my multi-select records i.e., Subs are 166..172
The issue is there is 168 in between the range displayed in the message. How can I show everything instead of range i.e. Subs are 166,168,172

Below is my code

trigger OnLookup(var Text: Text): Boolean
var
CitySubPg: Page Cities;
SubTab: Record Subs;
SelectionFilterManagement: Codeunit SelectionFilterManagement;
RecRef: RecordRef;
begin

CitySubPg.SetTableView(SubTab);
CitySubPg.LookupMode(true);
if CitySubPg.RunModal = ACTION::LookupOK then begin
CitySubPg.SetSelectionFilter(SubTab);
RecRef.GetTable(SubTab);


Message('Subs are %1', SelectionFilterManagement.GetSelectionFilter(RecRef, SubTab.FieldNo("SubCode")));

"CityCode" := SelectionFilterManagement.GetSelectionFilter(RecRef, SubTab.FieldNo(Code));
"SubCode" := SelectionFilterManagement.GetSelectionFilter(RecRef, SubTab.FieldNo("SubCode"));

end;
end;

Categories:
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,698 Super User 2024 Season 2 on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    Hi, I understand. If so you should try another solution.

    For example, using SelectionFilterManagement.GetSelectionFilter

                action(GetFilterForSelectedRecords)
                {
                    Caption = 'Get Filter For No.';
                    Promoted = true;
                    PromotedCategory = Process;
                    PromotedIsBig = true;
                    PromotedOnly = true;
                    ApplicationArea = All;
                    Image = GetOrder;
                    trigger OnAction()
                    var
                        SalesHeader: Record "Sales Header";
                        SelectionFilterManagement: Codeunit SelectionFilterManagement;
                        RecRef: RecordRef;
                    begin
                        SalesHeader.Reset();
                        CurrPage.SetSelectionFilter(SalesHeader);
                        RecRef.GetTable(SalesHeader);
                        Message(SelectionFilterManagement.GetSelectionFilter(RecRef, SalesHeader.FieldNo("No.")));
                    end;
                }

    Result:

    pastedimage1677741433080v1.png

    Just add a loop.

                action(GetFilterForSelectedRecords)
                {
                    Caption = 'Get Filter For No.';
                    Promoted = true;
                    PromotedCategory = Process;
                    PromotedIsBig = true;
                    PromotedOnly = true;
                    ApplicationArea = All;
                    Image = GetOrder;
                    trigger OnAction()
                    var
                        SalesHeader: Record "Sales Header";
                        SelectionFilterManagement: Codeunit SelectionFilterManagement;
                        RecRef: RecordRef;
                        FilterText: Text;
                    begin
                        FilterText := '';
                        SalesHeader.Reset();
                        CurrPage.SetSelectionFilter(SalesHeader);
                        RecRef.GetTable(SalesHeader);
                        if SalesHeader.FindFirst() then
                            repeat
                                if FilterText = '' then
                                    FilterText := SalesHeader."No."
                                else
                                    FilterText := FilterText   ','   SalesHeader."No.";
                            until SalesHeader.Next() = 0;
                        Message(FilterText);
                    end;
                }

    Result:

    pastedimage1677741735673v2.png

    Hope this helps.

    Thanks.

    ZHU

  • Romryan Profile Picture
    Romryan on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    ZHU,

    Yeah but in that message, I need the message to show everything, even the numbers in between the range. As per now instead of showing me 166,168,172 it shows 166..172.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,698 Super User 2024 Season 2 on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    Hi, It seems that this requirement is a bit similar to the test I did before. I hope the following information can give you some hints.

    How to get a filter for the selected records on any page (For example, ‘1..3|6’)

    https://yzhums.com/27561/

    pastedimage1677722493337v1.png

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    Then you have to first set the range for the records and then loop through them and build the filter string as you loop through the records that match your original filter.

    Maybe it is easier to help you if you share your complete code.

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

  • Romryan Profile Picture
    Romryan on at
    RE: GetSelectionFilter + SelectionFilterManagement issue

    Any suggestion?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans