How to automate the journals based on leave status in workflows AX2009

Hi,

I have customized workflow in Employee Leave Application Form.
First it is in open Status.After submitting the leave Appilication two people will approve. After approving this the status will changed to approve.
Once it is approved it will automatically creat a Payment journal based on Status and Absence Code. So where I will automate this.


I wrote the code in Table level modified method and Call the PayElementsDed() method.
if(this.LeaveStatus == PYLLeaveStatus::Approved)
{
if(this.getAbsenceCode() == ‘Sick’)
{

this.PayElementsDed(this.LeaveStatus, this.getAbsenceCode()
}
else if(this.getAbsenceCode() == ‘Emergency’)
{
this.PayElementsDed(this.LeaveStatus, this.getAbsenceCode()
}
else if(this.getAbsenceCode() == ‘Marriage’)
{
this.PayElementsDed(this.LeaveStatus, this.getAbsenceCode()
}
else if(this.getAbsenceCode() == ‘Dease’)
{
this.PayElementsDed(this.LeaveStatus, this.getAbsenceCode()

}

}

Public void PayElementsDed(PYLLeaveStatus Status,HRMAbsenceCodeId _Absence)
{
PYLEmplLeaveDetailsTable EmplLeaveDetailsTable;
PylPayrollJournalTable PayrollJournalTable;
PylPayrollJournalTrans PayrollJournalTrans;
PYLEmplPayElements PayElements;
PYLPeriodId _PeriodId = ‘Monthly’;
real _days;

PYLEmplAbsenceLedger EmplAbscenceLedger = new PYLEmplAbsenceLedger();
PYLEMplPayElements _PayElements = new PYLEMplPayElements();
;
ttsbegin;

PayrollJournalTable.JournalId = NumberSeq::newGetNum(HRMParameters::numRefPayrollJournalId()).num();
PayrollJournalTable.JournalNameId = ‘Absence’;
PayrollJournalTable.Description = ‘Absence Journal’;

PayrollJournalTable.insert();

//Generate the transaction line
PayrollJournalTrans.JournalId = PayrollJournalTable.JournalId;
PayrollJournalTrans.EmplId = this.EmplId;

PayrollJournalTrans.PeriodId = _periodId;
PayrollJournalTrans.PeriodFrom = DateStartMth(this.StartDate);
PayrollJournalTrans.PeriodTo = endmth(this.EndDate);
PayrollJournalTrans.JournalDescription = strfmt(“Absence Journal from %1 to %2”,this.StartDate,this.EndDate);

PayrollJournalTrans.PayElementCode = _Absence;//HRMAbsenceCodeId;//‘LeaveDed_Op’;
if(this.NoOfDays <= HRMAbsenceCode::find(this.getAbsenceCode()).NoOfDays)
{
_days = 0.00;
}
else
{
_days = this.NoOfDays - HRMAbsenceCode::find(_Absence).NoOfDays;
}
PayrollJournalTrans.Amount = -(_days * PYLEmplPayElements::getPerDayAbsenceSalaryAsOfDate(this.EmplId,_PeriodId,today(),_Absence));

PayrollJournalTrans.TransDate = today();

PayrollJournalTrans.insert();
info(strfmt(‘Journal Id:%1’,PayrollJournalTable.JournalId));
//Post the Journal
//ledgerJournalCheckPost= ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);
// ledgerJournalCheckPost.run();

//}
ttscommit;
}
I created a journal through job . It will create the lines. But this code I will call from modified or any other form and table methods, not reflecting any where.

Please suggest me where I will write this code for automate the journal lines based on Status and Absence Code.

Thanks,
Balu

Please suggest me

The completed event in related event handler class should trigger it.

Have look at \Classes\TSWorkflowElemEventHandler\completed

Thanks for reply

But I didn’t found any “TSWorkflowElemEventHandler” class in AX 2009

You must be having a class that handles the workflow events(to change the workflow status), the completed event should trigger the code to create payment journal.

see \Classes\PurchReqWorkflowEventHandler\completed. This will call the \Data Dictionary\Tables\PurchReqTable\Methods\setWorkflowState, this method handles the auto creation of purchase order, you can do the similar implementation.

Thanks Kranthi…

I found my class. same code I placed in Completed, Its working