Thursday, January 10, 2019

Dynamics AX create employee compensation (Fixed plan) through code X++

Hi,

Here is code to create employee compensation through code in Microsoft Dynamics AX. The method uses standard classes. All the variables starting with New* are parameters to create compensation.


private boolean createEmployeeFixedCompensation()
{
    boolean                                             ret = true;
    HRMCompFixedEmpl                     hRMCompFixedEmplInsert;
    HRMCompFixedPlanTable              hrmCompFixedPlanTable;
    HRMCompFixedEmplActionHire   hrmCompFixedEmplActionHire;

    try
    {

         if (NewActionId)
{
hrmCompFixedEmplActionHire = new HRMCompFixedEmplActionHire();

hRMCompFixedEmplInsert.PlanId   = NewPlanId;
hRMCompFixedEmplInsert.Worker  = NewHcmWorkerRecId;
hRMCompFixedEmplInsert.Status    = HRMCompFixedEmplStatus::Active;

hrmCompFixedPlanTable = HRMCompFixedPlanTable::find(NewPlanId);
hRMCompFixedEmplInsert.Type                   = hrmCompFixedPlanTable.Type;
hRMCompFixedEmplInsert.CurrencyCode    = hrmCompFixedPlanTable.CurrencyCode;
hRMCompFixedEmplInsert.PayFrequencyId = hrmCompFixedPlanTable.PayFrequencyId;

hRMCompFixedEmplInsert.ActionId       = NewActionId;
hRMCompFixedEmplInsert.Position        = NewHcmPosition;
hRMCompFixedEmplInsert.ValidFrom    = DateTimeUtil::date(NewEmploymentStartDate);
hRMCompFixedEmplInsert.ValidTo         = DateTimeUtil::date(NewEmploymentEndDate);
hRMCompFixedEmplInsert.PayRate        = NewPayRate;
hRMCompFixedEmplInsert.ProcessType = HRMCompProcessType::NonCyclical;

hRMCompFixedEmplInsert.doInsert();

HRMCompFixedEmplActionHire.parmHrmCompFixedEmpl(hRMCompFixedEmplInsert);
HRMCompFixedEmplActionHire.parmActionType(HRMCompFixedActionType::HireRehire);

HRMCompFixedEmplActionHire.run();

}
    }
    catch
    {
        exceptionTextFallThrough();
        ret = false;
    }
    return ret;
}


Have a good day :)

No comments:

Post a Comment