web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / How to select the newe...
Finance forum

How to select the newest data in DataEntity?

(0) ShareShare
ReportReport
Posted on by 972

Hi Everyone

          I created a DataEntity Extension(A), I also add a Table and a DataEntity to its DataSource. Now, everything is good, but some are repetitive because they have different Date.

          How can I add code to a DataEntity Extension to select the newest record if the records are repetitive?

Best Regards,

Jack

  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    What is repetitive ? Which entity did you extend ? Is that a valid time state table ?

  • Suggested answer
    Satish Panwar Profile Picture
    14,673 Moderator on at

    Hi Jack,

    You need to verify the relations for the table you added to make sure records are not repeating. Find what's causing record to duplicate and fix the source (probably through Joins between tables).

  • André Arnaud de Calavon Profile Picture
    307,166 Super User 2026 Season 2 on at

    Hi Jack,

    You had duplicated your question. For your answer have a look at your other thread: community.dynamics.com/.../357068

    The duplicate might be an accident. Please pay attention in future to prevent creating duplicates.

  • Suggested answer
    Pete Alberts Profile Picture
    3,546 on at

    I assume the datasource is from a VTS source. The "duplicates" you mentioned are because of a one-to-many relation that occurs because of the VTS fact.

    There is an option on the data entity datasource node named "Apply Date Filter". Set it to yes and then pull the ValidFrom and ValidTo fields into the data entity field list (you will get a compile time error if you don't).

    Then when you query the data entity you should get only the current valid record from the VTS table. And no more "duplicates".

    A good example is CustCustomerV3Entity: click Data Sources -> CustTable -> Data Sources -> DirPartyBaseEntity -> Data Sources -> LogisticsPostalAddressBaseEntity. Then notice the property "Apply Date Filter". Also DirPartyBaseEntity: DirPartyTable -> DirPersonForName -> DirPersonName

    Kind regards

  • JustZM Profile Picture
    972 on at

    Hi All Thanks for the answers.

             The duplicates data is caused from LogisticsPostalAddress because in some case LogisticsLocation.RecId has multiple LogisticsPostalAddress.Location. User creates new address, but system does not delete old address. I believe the relation between all tables should be correct. So I need to some code to do the rest. But this is my first time to code for DataEntity. I hope I can have some reference to learn it. I think I should use "insertEntityDataSource" method. But how can I use normal SQL language such as "Select, decrease, Increase, firstonly" on insertEntityDataSource?

    Best Regards,

    JustZM

  • André Arnaud de Calavon Profile Picture
    307,166 Super User 2026 Season 2 on at

    Hi JustZM,

    If you want to have just one record, you can set the relation to 1:1 on the datasource.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans