воскресенье, 26 февраля 2017 г.

Event handler for form datasource ax7

Hi, dear readers!
Recently I've had new task for Ax7, namely, I had to change behavior of one control on form. For this I must not customize current form, but extend it and create event handler to handle it. This was I done.
And below I just wanted to share with you some thoughts about  how we could do it faster and easier:

[FormDataSourceEventHandler(formDataSourceStr(WHSShipmentDetails, WHSShipmentTable), FormDataSourceEventType::Activated)]
    public static void WHSShipmentTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        WHSShipmentTable    shipmentTable = sender.cursor();  // our Args.record()
        //FormDataSource      shipmentDs = sender.formRun().dataSource(tableNum(WHSShipmentTable));      // in that way we could get DataSource to manipulate ds fields for example.
        FormControl         printConfirmControl = sender.formRun().design(0).controlName("ConfirmAndPrintShipmentRun"); //get control to change behavior
                printConfirmControl.enabled(WHSShipConfirm::isShipConfirmEnabledForShipment(shipmentTable));
    }

After creating new class, build the project and verify whether your event handler works or not.

Hope it'd be helpful!

Looking forward to seeing with you in new posts!