Tuesday, 22 June 2021

D 365 FO Enable or disable field based on condition using Extension Class

 [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchLine), FormDataSourceEventType::Activated)]

    public static void PurchLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        //Declaration of the Form Datasource

        FormDataSource              fds             = sender.formRun().dataSource(formDataSourceStr(PurchTable,PurchLine));

        PurchLine                   purchLine       = fds.cursor();

        FormRun                     fr              = sender.formRun();

        PurchParameters             purchParameters = PurchParameters::find();

        boolean                     allowEdit = true;

        //Form Tab page declaration for allowing to customize

        FormTabPageControl          ftpc = fr.design(0).controlName("TabLineFixedAsset");

        

        allowEdit = purchParameters.BER_AllowEditPOLineAfterReceipt;

        //condition

        if(PurchLine.PurchStatus == PurchStatus::Received)

        {

            //controls where the enable set true or false based on the condition execution

            fds.object(fieldNum(PurchLine ,PurchQty)).allowEdit(allowEdit);

            fds.object(fieldNum(PurchLine ,PurchPrice)).allowEdit(allowEdit);

            fds.object(fieldNum(PurchLine ,LineAmount)).allowEdit(allowEdit);

            fds.object(fieldNum(PurchLine ,DiscAmount)).allowEdit(allowEdit);

            fds.object(fieldNum(PurchLine ,DiscPercent)).allowEdit(allowEdit);

           //Fixed asset tab enable false if the Ststus is received.

            ftpc.allowEdit(false);

        }

    }


Thank you,

Keep Daxing :)

No comments: