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

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

(0) ShareShare
ReportReport
Posted on by 518

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

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    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.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    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.

  • Verified answer
    Mahmoud82 Profile Picture
    50 on at

    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();
    

  • Siddhant Singh Profile Picture
    518 on at

    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
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi,

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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans