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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

HcmWorkerRecId handling

(1) ShareShare
ReportReport
Posted on by 172
Hi,

When creating project quotation, there is a field that we can fill called WorkerSalesTaker. This field accepts workers that have a valid employment date.

So what I did, is first i looked for users email who have a person (to make sure email is unique)
Then i looked for workers in general even if they don't have a user, because project quotation allow adding a worker that doesn't have an email (i know that the system allows more than worker to have the same email, but there is nothing more to do, that's why I checked the user's person at first)

How can I simplify this or is what i did good?
    private void setWorkerSalesResponsible(LogisticsElectronicAddressLocator _email, SalesQuotationTable _salesQuotationTable)    {        HcmWorker                   hcmWorker;        LogisticsElectronicAddress  logisticsElectronicAddress;        Logisticslocation           logisticslocation;        DirPartyLocation            dirPartyLocation;        DirPerson                   dirPerson;        DirPersonUser               dirPersonUser;        userInfo                    userInfo;        select userInfo where userInfo.networkAlias == _email            join RecId from dirPersonUser where dirPersonUser.User == userInfo.id            join RecId from hcmWorker where hcmWorker.Person == dirPersonUser.PersonParty;        if(userInfo)        {            _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId;        }        else        {            select firstonly RecId from logisticsElectronicAddress                where logisticsElectronicAddress.Locator == _email                    && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email                join RecId from logisticslocation where logisticslocation.RecId == logisticsElectronicAddress.Location                join RecId from dirPartyLocation where dirPartyLocation.Location == logisticslocation.RecId                join RecId from dirPerson where dirPerson.RecId == dirPartyLocation.Party                join RecId from hcmWorker where hcmworker.Person == dirPerson.RecId;                if(hcmWorker)                {                    _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId;                }        }    }

Also DirPersonUserEntity has this where condition but I don't know from where it came as there are no ranges in the entity. And not sure if i should handle this in my above code

 
I have the same question (0)
  • Waed Ayyad Profile Picture
    9,133 Super User 2026 Season 1 on at
    private void setWorkerSalesResponsible(LogisticsElectronicAddressLocator _email, SalesQuotationTable _salesQuotationTable) {
      HcmWorker hcmWorker;
      LogisticsElectronicAddress logisticsElectronicAddress;
      Logisticslocation logisticslocation;
      DirPartyLocation dirPartyLocation;
      DirPerson dirPerson;
      DirPersonUser dirPersonUser;
      userInfo userInfo;
    
      select userInfo where userInfo.networkAlias == _email
      join
      RecId from dirPersonUser where
      dirPersonUser.User == userInfo.id
      join
      RecId from hcmWorker where hcmWorker.Person == dirPersonUser.PersonParty;
    
      if (userInfo) {
        _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId;
      } 
      else
      {
        select firstonly RecId from logisticsElectronicAddress where logisticsElectronicAddress.Locator == _email 
      && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email join RecId from logisticslocation where logisticslocation.RecId == logisticsElectronicAddress.Location join RecId from dirPartyLocation where dirPartyLocation.Location == logisticslocation.RecId join RecId from dirPerson where dirPerson.RecId == dirPartyLocation.Party join RecId from hcmWorker where hcmworker.Person == dirPerson.RecId; if (hcmWorker) { _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId; } } }
    I reformatted the code in order to read it better.
     
     
  • Suggested answer
    Waed Ayyad Profile Picture
    9,133 Super User 2026 Season 1 on at
    Hi,
     
    In order to get "workers that have a valid employment date." you should add HcmEmployment table to your query, 
     
    Select validTimestate(systemDateGet()) worker from hcmEmplyment
     join hcmWorker 
       where hcmEmplyment.Worker == hcmWorker.RecId
     join dirPersonUser
        where hcmWorker.Person == dirPersonUser.PersonParty
    join userInfo
        where  dirPersonUser.User == userInfo.id
         &&    userInfo.networkAlias == _email
     
    Give it a try and tell me the result.
     
    Thanks,
    Waed Ayyad
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
     
  • Suggested answer
    Waed Ayyad Profile Picture
    9,133 Super User 2026 Season 1 on at
    Hi 
     
    Is your issue resolved?
     
    Thanks,
    Waed Ayyad
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 356

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans