Hi guys,
I’m importing employees from excel file to AX, but i have a problem:
when I check after importing data, i observe that by the functional side, in the human resources - common - workers,
in general grid, there are workers imported.
If I try to open one of this workers imported, AX open the form (hcmWorker) but it show another worker, not the one that i have selected.
below i posted the code of two methods of my class and the class declaration.
Can someone help me, please?
thank’s in advanced.
class INT_ImportExcelClassWorker extends INT_ImportExcelClassBaseLavoratore
{
HcmPersonnelNumberId hcmPersonnelNumberId;
NumberSeq numberSeqPersonnelNum;
NumberSequenceReference numberSeqReferencePersonnelNum;
NumberSequenceTable numberSeqTablePersonnelNum;
CompanyInfo companyInfo;
DirPartyTable dirParty;
DirPerson dirPerson;
DirPersonName dirPersonName;
DirOrganization dirOrganization;
DirOrganizationBase dirOrganizationBase;
DirOrganizationName dirOrganizationName;
HcmActionState hcmActionState;
HcmActionTypeSetup hcmActionTypeSetup;
HcmEmployment hcmEmployment;
HcmWorker hcmWorker;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsLocation logisticsLocation;
LogisticsPostalAddress logisticsPostalAddress;
DictEnum enum;
dateDDMMYYYY data;
int lavoratore;
str city;
str cognome;
str contatto;
str countryRegionId;
str county;
str dataInizioImp;
str electronicAddress;
str name;
str nome;
str postalAddress;
str state;
str street;
str tipoIndirizzoElettronico;
HcmEmploymentType tipoLavoratore;
str zipCode;
}
public void importRow()
{
super();
this.numSequence(); //generate the personnel num
lavoratore = this.cell2Int(cells, row, 3);
if(lavoratore == 0)
{
tipoLavoratore = HcmEmploymentType::Employee;
}
else if(lavoratore == 1)
{
tipoLavoratore = HcmEmploymentType::Contractor;
}
this.importPerson();
this.importLavoratore();
}
public void importPerson()
{
dirPerson.clear();
dirPerson.initValue();
hcmWorker = HcmWorker::findByPersonnelNumber(hcmPersonnelNumberId, true);
if(!hcmWorker)
hcmWorker.PersonnelNumber = hcmPersonnelNumberId;
nome = this.cell2Str(cells, row, 1);
cognome = this.cell2Str(cells, row, 2);
name = nome + " " + cognome;
if(!hcmWorker.Person)
{
dirParty = DirPartyTable::find(DirPerson::find(hcmWorker.Person).PartyNumber);
if(dirParty)
{
dirParty = DirPartyTable::createNew(DirPartyType::Person, name, dirParty.PartyNumber);
}
else
{
dirPersonName.clear();
dirPersonName.initValue();
dirPersonName = DirPersonName::find(hcmWorker.Person, true);
dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
dirPersonName.FirstName = nome;
dirPersonName.LastName = cognome;
dirPerson.NameAlias = this.cell2Str(cells, row, 6);
dirPerson.Name = nome + " " + cognome;
dirPerson.insert();
dirPersonName.insert();
}
}
hcmWorker.Person = dirPerson.RecId;
hcmWorker.insert();
}
public void importLavoratore()
{
dataInizioImp = this.cell2Str(cells, row, 4);
data = str2Date(dataInizioImp, 123);
hcmEmployment = HcmEmployment::findByWorkerLegalEntity(hcmWorker.RecId, CompanyInfo::find().RecId, DateTimeUtil::minValue(), DateTimeUtil::maxValue(), true);
if(!hcmEmployment)
{
hcmEmployment.LegalEntity = CompanyInfo::find().RecId;
hcmEmployment.Worker = hcmWorker.RecId;
hcmEmployment.ValidFrom = DateTimeUtil::newDateTime(data, 0);
hcmEmployment.ValidTo = DateTimeUtil::maxValue();
hcmEmployment.EmploymentType = tipoLavoratore;
}
select * from hcmActionTypeSetup
where hcmActionTypeSetup.ActionType == HcmActionType::Hire;
hcmActionState.Originator = hcmWorker.RecId;
hcmActionState.ActionTypeSetup = hcmActionTypeSetup.RecId;
hcmActionState.ApprovalStatus = HcmApprovalStatus::Completed;
if(!hcmEmployment)
hcmEmployment.insert();
else
HcmWorkerTransition::newUpdateHcmEmployment(hcmEmployment, hcmEmployment.ValidFrom, hcmEmployment.ValidTo);
}