I had a scenario where I had to call a new method in one of the fields from Vendor Payment Journal Line.
The new method exists in Extension class of Vendor Payment journal.(which is a form method). This has to be called in modified method of the field ‘Ledger Dimension’.
The steps are as follows
[ExtensionOf(FormStr(LedgerJournalTransVendPaym))]
final class LedgerJournalTransVendPaymFormExt_Extension
{
public void newMethod()
{
……………….
}
}
How do call this method in modified ? you have two choices – Create a event handler for the method or Chain of Commands.
On using event handler, I ended up with error when I tried to call the new method using formRun.
[FormDataFieldEventHandler(formDataFieldStr(LedgerJournalTransVendPaym, LedgerJournalTrans, LedgerDimension), FormDataFieldEventType::Modified)]
public static void LedgerDimension_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource ledgerJournalTrans_ds = sender.datasource();
FormRun formRun= ledgerJournalTrans_ds.formRun();
formRun.newMethod();
}
Though I did not get any build errors , when navigating from the form I got the error ‘FormRun doesnot have the method ‘newMethod’.
So I went the latter approach and went ahead with creating Chain of Commands.
[ExtensionOf(formDataFieldStr(LedgerJournalTransVendPaym, LedgerJournalTrans , LedgerDimension))]
final class LedgerJournalTransVendPaymField_Extension
{
public void modified()
{
next modified();
element.newMethod();
}
}
Note the syntax of creating the extension class for data field in form.
Thus it is developers option to decide whether to use CoC or Event Handler.
Comments
Post a Comment