Monday, April 12, 2021

Listpage interaction class event handlers in D365fo

/// <summary>
/// This class is used to handle the event on SalesTableListPage form
/// </summary>
final class SM_Sales_SalesTableListPageInteractionEventHandler
{
    /// <summary>
    /// Sets the visibility property on the SM_SalesCalculateCumulativeGrossWeight button in the action pane.
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(SalesTableListPageInteraction), methodStr(SalesTableListPageInteraction, setButtonVisibility))]
    public static void SalesTableListPageInteraction_Post_setButtonVisibility(XppPrePostArgs args)
    {
        //CustParameters custParameters = CustParameters::find();

        //SalesTableListPageInteraction salesTableListPageInteraction = args.getThis();

        //salesTableListPageInteraction.listPage().actionPaneControlVisible(formControlStr(SalesTableListPage, SM_SalesCalculateCumulativeGrossWeight), custParameters.SM_ActivateSOGrossWeightCalculation);

    }

}
class LTSalesTableEventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]
    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        SalesTable          salesTable = sender.cursor();
        FormRun             element = sender.formRun();
        FormControl         sendPOToDeal = element.design(0).controlName("SendSOToDeal");
        FormControl         resendPOToDeal = element.design(0).controlName("ResendSOToDeal");
        
        if (salesTable.LTSOSent == NoYes::No && salesTable.SalesType == SalesType::Sales && salesTable.SalesStatus == SalesStatus::Backorder)
        {
            sendPOToDeal.enabled(true);
        }
        else
        {
            sendPOToDeal.enabled(false);
        }

        if (salesTable.LTSOSent == NoYes::Yes && salesTable.SalesType == SalesType::Sales && salesTable.SalesStatus == SalesStatus::Backorder)
        {
            resendPOToDeal.enabled(true);
        }
        else
        {
            resendPOToDeal.enabled(false);
        }

        if (salesTable.SalesType != SalesType::Sales)
        {
            sendPOToDeal.enabled(false);
            resendPOToDeal.enabled(false);
        }

    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(SalesTableListPageInteraction), methodStr(SalesTableListPageInteraction, selectionChanged))]
    public static void SalesTableListPageInteraction_Post_selectionChanged(XppPrePostArgs args)
    {
        SalesTableListPageInteraction salesTableInteraction = args.getThis();
        SalesTable  salestable  = salesTableInteraction.listPage().activeRecord(tableStr(SalesTable));

        if (salesTable.LTSOSent == NoYes::No && salesTable.SalesType == SalesType::Sales && salesTable.SalesStatus == SalesStatus::Backorder)
        {
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, SendSOToDeal), true);
        }
        else
        {
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, SendSOToDeal), false);
        }

        if (salesTable.LTSOSent == NoYes::Yes && salesTable.SalesType == SalesType::Sales && salesTable.SalesStatus == SalesStatus::Backorder)
        {
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, ResendSOToDeal),true);
        }
        else
        {
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, ResendSOToDeal), false);
        }

        if (salesTable.SalesType != SalesType::Sales)
        {
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, SendSOToDeal), false);
            salesTableInteraction.listPage().actionPaneControlEnabled(formControlStr(SalesTable, ResendSOToDeal), false);
        }

    }

}

/// <summary>
/// This class is used to handle the event on SalesTableListPageInteraction form
/// </summary>
[Extensionof(classStr(SalesTableListPageInteraction))]
final class SM_Sales_SalesTableListPageInteraction_Extension
{
    protected void setButtonVisibility()
    {
        next setButtonVisibility();

        CustParameters custParameters = CustParameters::find();
        
        this.listPage().actionPaneControlVisible(formControlStr(SalesTableListPage, SM_SalesCalculateCumulativeGrossWeight), custParameters.SM_ActivateSOGrossWeightCalculation);
    }

}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8