Importing a new Worker through code in ax 2012
public static void CreateEmployee(FirstName _firstName,
MiddleName _middleName,
LastName _lastName,
str _email,
HcmPersonnelNumberId _employeeId,
date _joiningDate,
HcmTitleId _title,
SelectableDataArea _ReleaseInCompany
)
{
HcmEmploymentType HcmEmploymentTypeloc;
DirPerson dirPerson;
DirPersonName dirPersonName;
HcmEmployment hcmEmployment;
HcmWorker newHcmWorker;
HcmWorkerTitle hcmWorkerTitle;
LogisticsLocation logisticsLocation;
LogisticsLocation lLogisticsLocation;
DirPartyContactInfoView dirPartyContactInfoView;
DirParty dirParty;
HcmEmploymentRecId newEmploymentRecId;
ValidFromDateTime employmentStartDateTime;
ValidToDateTime employmentEndDateTime;
str employeeEmailAdress;
HcmPersonnelNumberId employeeid;
RecId compayRecId;
container con;
str conitem;
int i;
Dialog dialog;
DialogField dialogFileName;
SysOperationProgress simpleProgress;
Filename filename;
FileIOPermission permission;
TextIO textIO;
HcmPersonnelNumberId hcmPersonnelNumberId;
NumberSequenceReference numberSeqReferencePersonnelNum;
NumberSequenceTable numberSeqTablePersonnelNum;
NumberSeq numberSeqPersonnelNum;
#File
#avifiles
dialog = new Dialog('Notepad Upload');
dialogFilename = dialog.addFieldValue(extendedTypeStr(FilenameOpen),filename,'File Name');
dialog.filenameLookupFilter(['.txt', #AllFiles]);
dialog.filenameLookupTitle('Upload from Text File');
dialog.caption('Upload from text file');
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
textIO = new TextIO(filename, #IO_READ);
textIO.inRecordDelimiter('\n');
textIO.inFieldDelimiter(',');
ttsBegin;
while(textIO.status() == IO_Status::Ok)
{
con = textIO.read();
conitem = conpeek(con,1);
//if(strlen(conitem) > 1)
//con = textIO.read();
//conitem = conpeek(con,1);
numberSeqReferencePersonnelNum = NumberSeqReference::findReference(extendedTypeNum(HcmPersonnelNumberId));
numberSeqTablePersonnelNum = NumberSequenceTable::find(numberSeqReferencePersonnelNum.NumberSequenceId);
if (numberSeqTablePersonnelNum)
{
numberSeqPersonnelNum = NumberSeq::newGetNumFromId(numberSeqTablePersonnelNum.RecId, true, true);
if(numberSeqPersonnelNum)
{
hcmPersonnelNumberId = numberSeqPersonnelNum.num();
}
}
_ReleaseInCompany = conPeek(con,5);
_firstName = conPeek(con,1);
_middleName = conPeek(con,2);
_lastName =conPeek(con,3);
_email = conPeek(con,4);
_title = conPeek(con,6);
HcmEmploymentTypeloc = conPeek(con,7);
_joiningDate = systemdateget();
_employeeId = hcmPersonnelNumberId;
dirPersonName.FirstName = _firstName;
dirPersonName.MiddleName = _middleName;
dirPersonName.LastName = _lastName;
employeeEmailAdress = _email;
employeeid = _employeeId;
compayRecId = CompanyInfo::findDataArea(_ReleaseInCompany).RecId;
employmentStartDateTime = DateTimeUtil::newDateTime(_joiningDate,24);
employmentEndDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::maxValue(), DateTimeUtil::getUserPreferredTimeZone());
if(!HcmWorker::findByPersonnelNumber(employeeid))
{
newHcmWorker = HcmWorker::find(HcmWorkerTransition::newCreateHcmWorker(dirPersonName
, employeeid
, compayRecId
, HcmEmploymentTypeloc
, employmentStartDateTime
, employmentEndDateTime));
dirPersonName.clear();
dirParty = new DirParty(DirPerson::find(dirPersonName.Person));
if(employeeEmailAdress != '' && newHcmWorker.Person != 0)
{
logisticsLocation.clear();
logisticsLocation = LogisticsLocation::create('Email', NoYes::No);
dirPartyContactInfoView.LocationName = 'Primay Email';
dirPartyContactInfoView.Locator = employeeEmailAdress;
dirPartyContactInfoView.Type = LogisticsElectronicAddressMethodType::Email;
dirPartyContactInfoView.Party = DirPerson::find(newHcmWorker.Person).RecId;
dirPartyContactInfoView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
}
if (newHcmWorker.RecId != 0)
{
ttsBegin;
hcmWorkerTitle.clear();
hcmWorkerTitle.Worker = newHcmWorker.RecId;
hcmWorkerTitle.ValidFrom = DateTimeUtil::newDateTime(_joiningDate,0);
hcmWorkerTitle.ValidTo = employmentEndDateTime;
hcmWorkerTitle.Title = HcmTitle::findByTitle(_title).RecId;
hcmWorkerTitle.insert();
ttsCommit;
}
if (newHcmWorker.RecId != 0)
{
info(newHcmWorker.PersonnelNumber+" Employee Created");
}
}
else
{
info(HcmWorker::findByPersonnelNumber(employeeid).PersonnelNumber+" already exists");
}
}
ttsCommit;
}
No comments:
Post a Comment