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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to update email in hcmworker Via a Job in AX 2012 R3 CU8

(1) ShareShare
ReportReport
Posted on by 9,315 User Group Leader

Hello Team,

In HR module for the number of worker's, we are looking to update just the email address.

I am looking for the code in which can update hcmworker.email from umeshp@goolge.com to umeshp@micorsoft.com.

How can this be achieved via the AX Job?

Any thoughts?

Thanks

Umesh

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Basheer17 Profile Picture
    2,720 on at

    Hi Umesh,

    If you want to update using job you can do it using below code.

    HcmWorker   hcmWorker;

       LogisticsElectronicAddress electronicAddress;

       DirPartyTable dirPartyTable;

       FieldId primaryFieldId = DirPartyTable::electronicAddressType2primaryFieldId(LogisticsElectronicAddressMethodType::Email);

       //--> Run this code in loop for multiple record update

       Select Person from HcmWorker where hcmworker.PersonnelNumber == '000095';

       if(hcmWorker.Person)

       {

           select firstonly electronicAddress

           exists join dirPartyTable

            where dirPartyTable.(primaryFieldId) == electronicAddress.RecId

               && dirPartyTable.RecId == hcmWorker.Person;

           electronicAddress.selectForUpdate(true);

           electronicAddress.Locator = 'admin@admin.com';

           electronicAddress.update();

       }

       //--> End

    The above job is for single worker, for multiple users run the above code in loop, get the data from excel, you will find the code to get data from excel on the internet.

  • Verified answer
    kathiravan Thirugnana sambandam Profile Picture
    375 on at
    static void changeEmail(Args _args)
    {
        LogisticsElectronicAddress  logisticsElectronicAddress;
        HcmWorker                   hcmWorker;
        DirPerson                   dirPerson;
        DirPartyTable               dirPartyTable;
     ttsBegin;
        logisticsElectronicAddress.selectforUpdate(true); 
       while select hcmWorker
        join dirPerson 
            where dirPerson.RecId == hcmWorker.Person
        join dirPartyTable
            where dirPartyTable.RecId == dirPerson.RecId
        join logisticsElectronicAddress
            where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId && logisticsElectronicAddress.locator == 'umeshp@goolge.com'
        {   
        logisticsElectronicAddress.locator = 'umeshp@micorsoft.com';
        logisticsElectronicAddress.update();
        }
       ttsCommit;
    }
  • Umesh Pandit Profile Picture
    9,315 User Group Leader on at

    Thanks This one worked for me only for a user. Need to find the users with @goolge.com replace with @micorsoft.com can this possible?

  • Verified answer
    kathiravan Thirugnana sambandam Profile Picture
    375 on at

    static void changeEmail(Args _args)

    {

       LogisticsElectronicAddress  logisticsElectronicAddress;

       HcmWorker                   hcmWorker;

       DirPerson                   dirPerson;

       DirPartyTable               dirPartyTable;

    ttsBegin;

       logisticsElectronicAddress.selectforUpdate(true);

      while select hcmWorker

       join dirPerson

           where dirPerson.RecId == hcmWorker.Person

       join dirPartyTable

           where dirPartyTable.RecId == dirPerson.RecId

       join logisticsElectronicAddress

           where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId && logisticsElectronicAddress.locator like '*@goolge.com'

       {

       //info(logisticsElectronicAddress.locator);

         logisticsElectronicAddress.Locator = strReplace(logisticsElectronicAddress.locator,'@goolge.com','@micorsoft.com');

         logisticsElectronicAddress.update();

       }

      ttsCommit;

    }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans