Mar 29, 2022

Button Click Event Handler in D365 FO

 class InventQuarantineParmEnd_Form_EventHandler

{   

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [FormControlEventHandler(formControlStr(InventQuarantineParmEnd, OK), FormControlEventType::Clicked)]

    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)

    {

        InventParmQuarantineOrder   InvParmQuarantineOrder;

        FormDataSource              formDataSource;


        RecId                   calendarRecId;

        FiscalCalendarPeriod    fiscalCalendarPeriod;

        TransDate               transDate;


        formDataSource = sender.formRun().dataSource(tableStr(InventParmQuarantineOrder));

        InvParmQuarantineOrder = formDataSource.cursor();



        if(InvParmQuarantineOrder.TransDate)

        {

            transDate = InvParmQuarantineOrder.TransDate;

            calendarRecId = Ledger::fiscalCalendar(CompanyInfo::find().RecId);

            fiscalCalendarPeriod = FiscalCalendarPeriod::findPeriodByCalendarDate(calendarRecId, transDate, FiscalPeriodType::Operating);

            if (fiscalCalendarPeriod.currentLedgerPeriodStatus() != FiscalPeriodStatus::Open)

            {

                throw error(strFmt("Date %1 is not open in Ledger calender. Please select date from open period", date2StrUsr(transDate, DateFlags::FormatAll)));

            }

           

        }

        if(!InvParmQuarantineOrder.TransDate)

        {

            throw error(strFmt("Please select date to proceed"));

        }

    }


}

No comments: