Wednesday, 27 May 2015

AX 2012 HCM Creating a Worker x++ code

Creating a worker in AX 2012

private HcmPersonnelNumberId nextPersonnelNumberId()
{
HcmPersonnelNumberId hcmPersonnelNumberId;
NumberSequenceReference numberSeqReferencePersonnelNum;
NumberSequenceTable numberSeqTablePersonnelNum;
NumberSeq numberSeqPersonnelNum;

// Number Sequence
numberSeqReferencePersonnelNum = NumberSeqReference::findReference(extendedTypeNum(HcmPersonnelNumberId));
numberSeqTablePersonnelNum = NumberSequenceTable::find(numberSeqReferencePersonnelNum.NumberSequenceId);

if (numberSeqTablePersonnelNum)
{
// generate worker personnel number if number sequence code is created.
numberSeqPersonnelNum = NumberSeq::newGetNumFromId(numberSeqTablePersonnelNum.RecId, true, true);

if(numberSeqPersonnelNum)
{
hcmPersonnelNumberId = numberSeqPersonnelNum.num();
}
}
return hcmPersonnelNumberId;
}

private void createHCMWorker()
{
AxDirPerson person;
AxDirPersonName personName;
HcmWorker worker;
HcmPersonnelNumberId hcmPersonnelNumberId;

hcmPersonnelNumberId = this.nextPersonnelNumberId();

if (!hcmPersonnelNumberId)
return;

// Create a person
person = AxDirPerson::construct();
person.parmName("Santa Claus");
person.save();

personName = AxDirPersonName::construct();
personName.parmPerson(person.dirPerson().RecId);
personName.parmFirstName(person.dirPerson().Name);
personName.parmValidTo(DateTimeUtil::maxValue());
personName.save();

// Create the worker
HcmWorkerTransition::newCreateHcmWorker(personName.dirPersonName(), hcmPersonnelNumberId);
}

No comments:

Post a Comment

AZURE INTERVIEW QUESTIONS AND ANSWERS

AZURE INTERVIEW QUESTIONS AND ANSWERES 2021 2. What is cloud computing? Explanation:  It is the use of servers on the internet to “store...