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:
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:
- Create a Service Group in AOT
- Rename it to HcmWorkerImportDemo
- Drag the "HcmWorkerImportService" into your newly created service group.
- Right Click on the "HcmWorkerImportDemo" & click on Deploy Service Group.
- Go to System Administration -> Setup -> Services & Application Integration Framework -> Inbound Ports
- Find your "HcmWorkerImportDemo" Inbound port & Copy the WSDL Address.
- Create a C# Console Application.
- Right click on your solution -> add Service Reference -> Paste the WSDL Address
- Type the Reference Name like "ABC"
- Include ABC as a namespace.
- 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 !!!
Hi,
ReplyDeleteIts working fine,But i am getting following issue
When i am trying to add employee first time it was inserted successfully.second time i am trying to insert another record its showing already record exist.
what is the problem..
Thanks inadvance...
regards,
somu
Hi,
ReplyDeleteUse with different GUID then it should work fine.
Hi Kuldeep,
ReplyDeleteis it possible to add a old sales transaction done in 2008 into AX 2012 using WCF service?
After this import, this transaction should reflect in the sales achieved.
Regards
Akash
If you get the employee exists, its because there's an entry in the HCMEMPLOYMENTEMPLOYEE table where its set the record to 0 for the Employment column. This table is used for storing info like pension start dates etc, if you dont need it then you can comment out these lines in the class AxdHCMWorkerImport class, method prepareForSaveExtended
ReplyDelete// Ensure HcmEmployment record is saved
case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:
if (axHcmEmployment.parmEmploymentType() == HcmEmploymentType::Employee)
{
// hcmEmploymentEmployee.ValidFrom = axHcmEmployment.parmValidFrom();
// hcmEmploymentEmployee.ValidTo = axHcmEmployment.parmValidTo();
// hcmEmploymentEmployee.Employment = axHcmEmployment.parmRecId();
// hcmEmploymentEmployee.insert();
}
else if (axHcmEmployment.parmEmploymentType() == HcmEmploymentType::Contractor)
{
// hcmEmploymentContractor.ValidFrom = axHcmEmployment.parmValidFrom();
// hcmEmploymentContractor.ValidTo = axHcmEmployment.parmValidTo();
// hcmEmploymentContractor.Employment = axHcmEmployment.parmRecId();
// hcmEmploymentContractor.insert();
}
Save and compile and reload the service.
How to do update as dirpersonname has date-effective-data field? The C# for update is throwing 'Invalid conversion' error
ReplyDeleteKeyField DirPersonNameKeyField1 = new KeyField { Field = "RecId", Value = "52565428785" };
EntityKey DirPersonNameEntityKey = new EntityKey() { KeyData = new[] { DirPersonNameKeyField1 } };
EntityKey[] DirPersonNamesEntityKeys = new EntityKey[1] { DirPersonNameEntityKey };
var pre = client.read(ctx, DirPersonNamesEntityKeys);
var lastLine = pre.HcmWorker[0].DirPerson.DirPersonName;
var DirPName= new AxdEntity_DirPersonName()
{
RecId = lastLine.RecId,
RecIdSpecified = true,
RecVersion = lastLine.RecVersion,
ValidFrom=lastLine.ValidFrom,
LastName="new",
action = AxdEnum_AxdEntityAction.update,
actionSpecified = true,
};
var HWorker=new AxdEntity_HcmWorker()
{
_DocumentHash=pre.HcmWorker[0]._DocumentHash,
RecId=pre.HcmWorker[0].RecId,
RecIdSpecified=true,
RecVersion=1,
RecVersionSpecified=true,
action = AxdEnum_AxdEntityAction.update,
actionSpecified = true,
DirPerson = new[] {to(DirPName)}, // error is thrown here
};