Skip to main content

Notifications

Announcements

No record found.

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

How to filter for a max-date in the lookup?

(1) ShareShare
ReportReport
Posted on by 26
Hello guys,
 
here's what I'm up to:
 
 
I have created a new table. There are the fields Code, Cost center, Valid from and Description.
 
In the table I have now entered three rows:
 
A001 C001 29.08.23 Test 1
A002 C001 01.09.23 Test 2
A003 C002 28.08.23 Test 3
 
 
Now I have created a new field in the sales order called Department. There the code A001 should be displayed if the document date of the order is identical to the values from the new table.
 
The sales order has the document date 29.08.23.
 
So the field should contain A001, because today is 08/29/23.
 
A003 has a different cost center and is too small by date and for A002 the date is not valid as of today.
 
I want to display the values in the orders via a lookup.
 
How can I build a date filter with MAX here?
 
I make a setrange on the new table where I filter on cost center, which must be as in the order.
 
Then two rows remain:
 
A001 C001 29.08.23 Test 1
A002 C001 01.09.23 Test 2
 
Now I make a findlast and should have only the last row.
Whose value in code I want to have in the order.
But unfortunately does not work. What am I doing wrong? Where do I have to program it and how?
 
 
Thank you.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    How to filter for a max-date in the lookup?
    Hi, I'm sorry that I didn't fully understand your needs. If you need to create a Lookup list with filtered results, you can consider using the following method.
    You can add the filter you need before RunModal method.
     
    If you just want to find the last date, you need to sort by date before findlast. You can use the following two methods to get the correct ordering.
    Record.Ascending([Boolean]) Method
     
    Hope this can give you some hints.
    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

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,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/globalsearch/?q=bBBzgzvz+zz+vzbzbzzbx+xbxbxbbxx++%2C+xbbxbxvxx+bzbzxnzb" - Nested quantifier +.