D365F&O - X++ - How to Enable/Disable button on form based on a condition in D365F&O using Event handlers.
1- Create a new class SalesOrderFormEventHandlers.
2- Go to SalesTable form.
3- Expand SalesTable datasource.
4- Expand Events, right click on OnActivated and click on Copy event handler method.
class SalesOrderFormEventHandlers
{
/// <summary>
/// Enable or disable Refund button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormEventHandler(formStr(SalesTable), FormEventType::Activated)]
public static void SalesTable_OnActivated(xFormRun sender, FormEventArgs e)
{
// Button control name in your form design
#define.BUTTONNAME('JWRefundButton')
FormDataSource form_ds = sender.dataSource(formdatasourcestr
(SalesTable, SalesTable));
// Get selected sales order record
SalesTable salesOrder = form_ds.cursor();
// Disable the button if the sales status of selected record is Canceled
FormFunctionButtonControl RefundButtonControl = sender.control(
sender.controlId(#BUTTONNAME));
RefundButtonControl.enabled(salesOrder.SalesStatus == SalesStatus::Canceled);
}
}
Comments
Post a Comment