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 :)

D365FO Create Workflows on existing form with Extension

You need to know:
Dynamics 365 for Finance and Operations (AX 7) allows us to extend its functionality through creating extension of elements or creating new elements. Unlike previous versions where we could easily open any OOTB element do whatever changes we wanted (i.e. Customization), D365FO stops us change its OTTB elements through its best practices rules and more extension oriented architecture.

Problem statement:
We can create workflows on both new forms and existing OOTB forms. Because authoring workflows need to modify forms and source table on which workflow is needed we cannot use extension method to enable workflows on existing forms.

Solution summary:
We will create a new table which hold the primary key/ RECID of the target form primary table and the workflow status enum only. Also we perform all workflow related business logic on that table. We then add that table on Data source of the target form which will eventually enable workflow. 
Here is the detail process:







5. Authoring workflows:
Then as usual create workflows on the just created table.



Create workflow category, Query, Type and approval elements. For my practice I created workflow on Transfer order.