Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support teams Worldwide

Calling the HcmWorkerImportService in AX 2012 to Import Employees

Calling the HcmWorkerImportService in AX 2012 to Import Employees

Rate This
  • Comments 4

In cumulative update 2 (CU2) for AX 2012 we shipped an HcmWorkerImportService which allows you to import full-time employees and vendors.  The code below is an example of how to call the worker service from C#:

            HcmWorkerImportServiceClient proxy = new HcmWorkerImportServiceClient();
            CallContext context = new CallContext();
            context.Company = "ceu";

            AxdHcmWorkerImport worker = new AxdHcmWorkerImport();
            AxdEntity_HcmWorker hcmWorkerTable = new AxdEntity_HcmWorker();
            AxdEntity_DirPerson_DirPerson party = new AxdEntity_DirPerson_DirPerson();
            party.NameAlias = "rnewell";
            party.Gender = AxdEnum_Gender.Female;
            party.MaritalStatus = AxdEnum_DirPersonMaritalStatus.Married;

            AxdEntity_DirPersonName personName = new AxdEntity_DirPersonName();
            personName.FirstName = "Rebecca";
            personName.MiddleName = "Kay";
            personName.LastName = "Newell";

            party.DirPersonName = personName;

            hcmWorkerTable.DirPerson = party;

            AxdEntity_HcmEmployment personEmployment = new AxdEntity_HcmEmployment();
            personEmployment.EmploymentType = AxdEnum_HcmEmploymentType.Employee;
            personEmployment.LegalEntity = "ceu";

            hcmWorkerTable.HcmEmployment = new AxdEntity_HcmEmployment[1] { personEmployment };

            worker.HcmWorker = new AxdEntity_HcmWorker[1] { hcmWorkerTable };

                proxy.create(context, worker);

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • I found this code only worked once for me, it added one employee but then had an exception error on another saying the record already existed. I chased this down, I found this was because there were no existing employees in the table HCMEmploymentEmployee, the first record added to this table creates a value of Zero in the employment column, so when a new one is created it finds it to be zero and says it already exists, I could not find a code work around, but I found that once I created a single correct entry in this table it worked thereafter. To create a record in this table you need to go into any employee in AX and add data to the employee ->Employment -> Employment Details (Pension Plan start date etc) once this is done the code above works everytime.

    Hope that makes sense...

  • I am trying to use this code to import employees,  The AxdWorkerImport\prepareForSaveExtended code fails as the HcmEmploymentRecId has not yet been saved to the table and is not present in the class, when a record is being inserted into HcmEmploymentEmployee at code line # 128 during the processing context of 'AfterAllChildRecordsProcessed with the datasource of HcmEmployment.

    Any advise would be greatly appreciated.

  • Hi Tim,

    Can you use the steps Wayne outlined above?

  • Is it possible to add the email for the current Worker through this service?

    AxdEntity_DirPersonName personName = new AxdEntity_DirPersonName();

               personName.FirstName = _firstName;              // FirstName

               personName.MiddleName = _middleName;            // MiddleName

               personName.LastName = _lastName;                // LastName

               party.DirPersonName = personName;

               AxdEntity_DirPartyContactInfoView contactInfo = new AxdEntity_DirPartyContactInfoView();

               contactInfo.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;

               contactInfo.Locator = "";

               party.DirPartyContactInfoView = new AxdEntity_DirPartyContactInfoView[] { contactInfo };

               hcmWorkerTable.DirPerson = party;

Page 1 of 1 (4 items)