Reputation: 7
I have to calculate the Net Amount on Sales Order Line by adding the number of months for which the item will be sold on that price. For this purpose, I have created extension of the form SalesTable and used the event handler OnValidating for the Data Field 'Line Amount'. Following is the code I have written:
[Extensionof(formStr(SalesTable))]
final class PRMSC_SalesLine_Extension
{
//<summary>
//</summary>
//<param name="sender"></param>
//<param name="e"></param>
[FormControlEventHandler(formControlStr(SalesTable, SalesLine_LineAmount), FormControlEventType::Validating)]
public static void SalesLine_LineAmount_OnValidating(FormControl sender, FormControlEventArgs e)
{
SalesLine _salesLine;
_salesLine.LineAmount = (_salesLine.SalesPrice)*(_salesLine.SalesQty)*(_salesLine.PRMSC_NoOfMonths);
FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;
cancelableSuperEventArgs.CancelSuperCall();
}
}
The build and DB sync went fine without errors but still the calculation of line amount does not include the number of months field
Upvotes: 0
Views: 214
Reputation: 371
You have no data in the _salesLine, init the buffer:
FormRun formRun = sender.formRun() as FormRun;
FormDataSource salesLine_ds = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine)) as FormDataSource;
SalesLine _salesLine = salesLine_ds.cursor();
Upvotes: 0