Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

How to get user worker relation for past workers?

Posted on by 93
Hi All,

I have written this piece of code to get user associated with worker.
Its working fine for active employees. For past worker the data not available in the dirperson table.
But in front end i can see the record with past worker associated with the user.

Please help me how to get user worker relation for past workers?
  DirPersonUser personUser  =   DirPersonUser::findParty(worker.Person); this.UserID               =   personUser.User;
Thanks in advance
  • PJ JohnPaul Profile Picture
    PJ JohnPaul 93 on at
    How to get user worker relation for past workers?
    Thank you so much Andre.
  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,113 Super User 2024 Season 2 on at
    How to get user worker relation for past workers?
    Hi JohnPaul,
     
    The table DirPersonUser is a table enabled for date effectiveness. In that case, by default, it will only select records currently active. If the record for the worker has an end date before the current date or a start date after the current date, it will not be selected. You can use an alternative way of finding the record, providing a range for effective records, e.g.
     
    DirPersonUser  dirPersonUser;
    utcDateTime    dateFrom;
    utcDateTime    dateTo = DateTimeUtil::utcNow(); 
     
    select firstonly validTimeState(dateFrom, dateTo) from dirPersonUser
        order by dirPersonUser.ValidTo desc
        where dirPersonUser.PersonParty == worker.Person;
    
    this.UserID = dirPersonUser.UserID;
     

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 Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans