Friday, June 15, 2012

HcmWorkerImportService to create/import worker into AX 2012

Hi All,
         Today we will be having a look at the AIFDocumentServices to create Worker (Contractor/Employee) into AX 2012 using HcmWorkerImportService.

Pre-requisites:
1) AX 2012 with CU2
2) Demo Data
3) Visual Studio Dev Tools

Scenario:
Wants to create/import worker into AX 2012 from an external application.

Solution:

  1. Create a Service Group in AOT
  2. Rename it to HcmWorkerImportDemo
  3. Drag the "HcmWorkerImportService" into your newly created service group.
  4. Right Click on the "HcmWorkerImportDemo" & click on Deploy Service Group.
  5. Go to System Administration -> Setup -> Services & Application Integration Framework -> Inbound Ports
  6. Find your "HcmWorkerImportDemo" Inbound port & Copy the WSDL Address.
  7. Create a C# Console Application.
  8. Right click on your solution -> add Service Reference -> Paste the WSDL Address
  9. Type the Reference Name like "ABC"
  10. Include ABC as a namespace.
  11. Modify the main() method with the below code :
            HcmWorkerImportServiceClient proxy = new HcmWorkerImportServiceClient();
            CallContext context = new CallContext();
            context.Company = "ceu"; //Company Name

            AxdHcmWorkerImport worker = new AxdHcmWorkerImport();
            AxdEntity_HcmWorker hcmWorkerTable = new AxdEntity_HcmWorker();

            AxdEntity_DirPerson_DirPerson party = new AxdEntity_DirPerson_DirPerson();
            party.NameAlias = "Kuldeep";
            party.Gender = AxdEnum_Gender.Male;
            party.MaritalStatus = AxdEnum_DirPersonMaritalStatus.Married;

            AxdEntity_DirPersonName personName = new AxdEntity_DirPersonName();
            personName.FirstName = "Kuldeep";
            personName.MiddleName = "Singh ";
            personName.LastName = "Godara";
            party.DirPersonName = personName;

            hcmWorkerTable.DirPerson = party;

            AxdEntity_HcmEmployment personEmployment = new AxdEntity_HcmEmployment();
            personEmployment.EmploymentType = AxdEnum_HcmEmploymentType.Contractor;
            personEmployment.LegalEntity = "ceu"; //Company Name

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

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

            try
            {
                proxy.create(context, worker);
                Console.WriteLine("Success");
                Console.ReadLine();
            }
            catch
            {
                throw;
            }
12. Run the Application.
13. Cross Check your worker into AX 2012.


Enjoy DAX !!!