Notifications
Announcements
No record found.
Hi experts,
I don't want to import worker. I have name and other related information of a worker. I need to create a worker through X++.
*This post is locked for comments
Try it:
www.andesoft.net/create-employee-using-x-code
long back I wrote some code for that. Let me share that, you may modify that as per your needs
Here it goes
public static void CreateEmployee(FirstName _firstName, MiddleName _middleName, LastName _lastName, str _email, HcmPersonnelNumberId _employeeId, date _joiningDate, HcmTitleId _title, SelectableDataArea _ReleaseInCompany) { DirPerson dirPerson; DirPersonName dirPersonName; HcmWorker newHcmWorker; HcmWorkerTitle hcmWorkerTitle; LogisticsLocation logisticsLocation; LogisticsLocation lLogisticsLocation; DirPartyContactInfoView dirPartyContactInfoView; DirParty dirParty; HcmEmploymentRecId newEmploymentRecId; ValidFromDateTime employmentStartDateTime; ValidToDateTime employmentEndDateTime; str employeeEmailAdress; HcmPersonnelNumberId employeeid; RecId compayRecId; ; 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 , HcmEmploymentType::Employee , employmentStartDateTime , employmentEndDateTime)); 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"); } }
Thanks Sohaib.
HI Sohaib,
i am also looking for same thing but i also want to include marital status and numberofdependent fields but they are in hcmPersonDetails table. how can i incorporate them. kindly guide me.
Thanks
Hi xain,
Divide your task into two parts
1) create worker
2) import hcmPersonDeatils
if I will be in your shoes, I will love to rely on DIXF. Writing code is just a matter of wasting time, if something is available as data entity. Have a look at entities, if you can use one or you may create a custom entity.
have a look at things that i have tried but couldn't get it figure out.
addingfieldserror.rar
P.S. i also had posted my question on this thread.
https://community.dynamics.com/ax/f/33/p/251405/702934#702934
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 4 Most Valuable Professional
Priya_K 4
MyDynamicsNAV 2