Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Create a custom view and make it the default view

(1) ShareShare
ReportReport
Posted on by 227
Hello!
I would like to create a custom view to my Sales Quotes page. I fiddled around with it, and used the OnOpenPage trigger to set a filter on the page to display the Sales Quotes that are connected to the current logged in user. This is my trigger:
 
trigger OnOpenPage()
    begin
        User.SetRange("User Name", UserId);
        if User.FindFirst() then begin
            SalesPerson.SetRange(Name, User."Full Name");
            if SalesPerson.FindFirst() then begin
                Quotes.SetFilter("Salesperson Code", SalesPerson.Code);
                CurrPage.SetTableView(Quotes);
            end;
        end;
    end;
 
 
When I finished, I figured it would be a much better solution to create a view instead, so I went back to my pageextension and made this:
 
views
    {
        addlast
        {
            view(MyQuotes)
            {
                Caption = 'My Sales Quotes';
                Filters = where ("Salesperson Code" = filter (= "CURRENT LOGGED IN SALESPERSON")))
            }
        }
    }
 
But I can't for the life of me figure out how I can filter with a variable, or if that is even possible. 
 
I tried creating global variables to store the current User and SalesPerson, in hopes I could use it in the view, but I struggle a bit with this one, to be honest.
 
Is there any way to create a view in AL that filters the Quotes with the filter I want, and is it possible to make it the default view for the page?
  • gdrenteria Profile Picture
    gdrenteria 12,290 Most Valuable Professional on at
    Create a custom view and make it the default view
    Hi
    (%me or %user) Records Assigned to You
    Best
    GR
  • Suggested answer
    Andy Wingate Profile Picture
    Andy Wingate 320 on at
    Create a custom view and make it the default view
    Hello 
     
    "So in reality there is no way to get the current logged in user, and find their SalesPerson code, and create a view for it the way I would've liked here?"
     
    Yes you can - if you take a mix of the soluton from Yun Zuh  - i.e. ask users to click a URL that will open a specific view.
     
    AND 
     
    you set your salesperson codes to be the same as the user.name of the sellers
     
    AND
     
    create a filter view where you set the Salesperson Code = %user


     

     
    %user% always resolves to the logged in user, so thats why you need to match up usernames and sales person codes
     
     
    The only issue you might have is if you have very long usernames!
     
    Hope this helps
     
    Andy
     
     
  • Hagru Profile Picture
    Hagru 227 on at
    Create a custom view and make it the default view
    So in reality there is no way to get the current logged in user, and find their SalesPerson code, and create a view for it the way I would've liked here?
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,036 Super User 2024 Season 2 on at
    Create a custom view and make it the default view
    This can be associated with fields, but not with variables.
    For default view: Dynamics 365 Business Central: How to set the default view/layout for a list page (Predefined List View)
     
    Hope this helps.
    Thanks.
    ZHU

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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans