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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to get user worker relation for past workers?

(0) ShareShare
ReportReport
Posted on by 97
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
I have the same question (0)
  • PJ JohnPaul Profile Picture
    97 on at
    How to get user worker relation for past workers?
    Thank you so much Andre.
  • Verified answer
    André Arnaud de Calavon Profile Picture
    298,933 Super User 2025 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,258

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 949 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 631 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans