Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Want to insert a record in contact information of employee using Job

(0) ShareShare
ReportReport
Posted on by 510

Hi All,

Want to insert a record in LogisticsElectronicAddress using below job. Record is inserted in table but not showing in form of Employee and in not showing in HcmWorker.email().

Can any one have idea why its not working.

pastedimage1595510922274v1.png

static void changeEmail(Args _args)
{
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsLocation logisticsLocation;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable dirPartyTable;
ttsBegin;
//logisticsElectronicAddress.
logisticsElectronicAddress.selectforUpdate(true);
select hcmWorker
join dirPerson
where dirPerson.RecId == hcmWorker.Person
&& hcmWorker.PersonnelNumber == "3081"
join dirPartyTable
where dirPartyTable.RecId == dirPerson.RecId;
//join logisticsElectronicAddress
//where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId ;
{
logisticsElectronicAddress.Description = "Email ID";
logisticsElectronicAddress.locator = "Singh@gmail.com";
logisticsElectronicAddress.Type = LogisticsElectronicAddressMethodType::Email;
logisticsElectronicAddress.IsPrimary = true;
logisticsLocation.Description = "3081";
logisticsLocation.IsPostalAddress = NoYes::Yes;
logisticsElectronicAddress.insert();
}
ttsCommit;
}

Thanks and regards

Siddhant Singh

  • Verified answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Want to insert a record in contact information of employee using Job

    Hi,

    yes, also LogisticsLocation can be created when DirPartyLocation::findOrCreate is called - you can see this by looking into that method.

  • Siddhant Singh Profile Picture
    510 on at
    RE: Want to insert a record in contact information of employee using Job

    Hi Nikolaos/Mohmoud,

    Below code is working fine. 

    One more thing I want to ask, by inserting data from job in table LogisticsElectronicAddress and DirPartyLocation, will it effect any other table. 

    static void employeeEmailUpdate(Args _args)
    {
        LogisticsElectronicAddress  logisticsElectronicAddress;
        LogisticsLocation           logisticsLocation;
        HcmWorker                   hcmWorker;
        DirPerson                   dirPerson;
        DirPersonUser               dirPersonUser;
        DirPartyTable               dirPartyTable;
        Email                       email;
        ttsBegin;
        logisticsElectronicAddress.selectforUpdate(true);
        select hcmWorker
        join dirPerson
            where dirPerson.RecId == hcmWorker.Person
            && hcmWorker.PersonnelNumber == "740670"
            //&& hcmWorker::findByPersonnelNumber(hcmWorker.PersonnelNumber)
        join dirPersonUser
            where dirPersonUser.PersonParty == dirPerson.RecId
        join dirPartyTable
            where dirPartyTable.RecId == dirPerson.RecId;
        if(hcmWorker)
        {
            logisticsElectronicAddress.Description = "Email ID";
            email = SysUserInfo::find(dirPersonUser.User).Email;
            logisticsElectronicAddress.locator = email;
            logisticsElectronicAddress.Location = DirPartyLocation::findOrCreate(Hcmworker.person, 0).Location;
            logisticsElectronicAddress.Type = LogisticsElectronicAddressMethodType::Email;
            logisticsElectronicAddress.IsPrimary = NoYes::Yes;
            //logisticsElectronicAddress.IsPrivate = NoYes::No;
            if(logisticsElectronicAddress.validateWrite())
                logisticsElectronicAddress.insert();
        }
        ttsCommit;
    }

    Thanks and regards

    Siddhant Singh

  • Verified answer
    Mahmoud82 Profile Picture
    50 on at
    RE: Want to insert a record in contact information of employee using Job

    hello Siddhant

    I think you missed to call the function DirPartyLocation::findOrCreate() to create the location frist, then you can assgin the return value of this function to "Location" filed of "LogisticsElectronicAddress" table 

    here is the sample code 

        Hcmworker   Hcmworker;
        LogisticsElectronicAddress elecAddress;
        ;
        elecAddress.clear();
        elecAddress.Type = LogisticsElectronicAddressMethodType::Email; // for phone type should be phone
        elecAddress.Locator = "Test@Test.com"; // for phone number give the new Phone number
        elecAddress.IsPrimary = NoYes::Yes;
        elecAddress.Location = DirPartyLocation::findOrCreate(Hcmworker.person, 0).Location;
        if(elecAddress.validateWrite())
            elecAddress.insert();
    

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Want to insert a record in contact information of employee using Job

    Anyway you could simply use LogisticsElectronicAddress.createElectronicAddressFromUnsolicited method - I haven't tried it but seems that it does all the work for you.

    At least you can use it as an example for your code.

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Want to insert a record in contact information of employee using Job

    Hi,

    please use "Use rich text formatting" -> "Insert" -> "Code" to share your code, then it's easier to read.

    Your code looks quite confusing. I don't see any logic that would link the inserted address to the employee, so it definetely will not show up in the employee's details.

    You also set some fields to logisticsLocation, but it's never inserted.

    And what is the purpose of the select statement? You are not using the selected data for anything in your code.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,138 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans