The best way to create MIcrosoft Dynamics AX entities from code is to use standard Dynamics AX document services. It is a safest way to make sure that all business logic is performed, and everything is created correctly. This article describes how to create earning statement using standard Dynamics AX document service.
This example will create earning statement for worker with personnel number 000001, for Pay cycle BW (BiWeekly) and pay period September 13th – September 26th. Earning date must be a date in pay period, in this case September 15th.
Position must be assigned to worker for which the statement is created. Earning code can be one of the earning codes assigned to a worker and positon (Each worker can have several earning codes for the position.
Earning quantity is number of hours.
static void insertPayrollEarningStatements()
PayrollPayPeriodKey period = new PayrollPayPeriodKey();
PeriodStart periodStart = mkDate(13, 9, 2015);
PeriodEnd periodEnd = mkDate(26, 9, 2015);
PayrollEarningCodeId earningCode = ’01’;
DataAreaId dataAreaId = ’01’;
PersonnelNumber personnelNumber = ‘000001’;
PayrollPayCycleId payCycleId = ‘BW’;
TransDate earningDate = mkDate(15, 9, 2015);
HcmPositionId positionId = ‘POS0001’;
PayrollEarningQuantity earningQuantity = 1;
info(“Import of Earning statements started”);
service = PayrollEarningsImportService::construct();
statement = new PayrollEarningsImport();
earningStatement = statement.createEarningStatement().addNew();
earningStatementLine = earningStatement.createEarningStmtLine().addNew();
info(“Import of Earning statements finished”);