Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Create a custom view and make it the default view

Posted on by 209
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?
Categories:
  • gdrenteria Profile Picture
    gdrenteria 9,942 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 312 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 209 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 70,191 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans