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

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 };

            try
            {
                proxy.create(context, worker);
            }
            catch
            {
                throw;
            }