Wednesday 30 September 2020

Customize Sales Totals form in D365 FO (AX)

Customize Sales Totals form in D365 FO (AX)

Today, I am going to share with you that how to override Sales tax in Sales Totals form based on condition.

Here, my requirement is- If (SalesTable.HSChangedInD365 == NoYes::No) then Sales Totals form should display the tax what we have received through web service (Or, order import through from party API) otherwise it should display the standard calculated tax. So I have overridden the tax value when values are initializing in container.

Here, we go...

/// <summary>
///     this is the extension class of SalesTotals class.
/// </summary>
[ExtensionOf(classStr(SalesTotals))]
final class SalesTotalsLFI_Extension
{
    /// <summary>
    ///     this is the COC of SalesTotals.displayFieldsServer()
    ///     to modify container and initialize Total sales tax and updated Invoice amount based on below condition.
    /// </summary>
    /// <param name = "_orderTable">Caller table to calculate totals for.</param>
    /// <param name = "_specQty">Quantity to calculate totals for.</param>
    /// <param name = "_currencyCode">Currency code to calculate totals for.</param>
    /// <returns>
    /// Container of the field values to be shown on the totals form.
    /// </returns>
    static public container displayFieldsServer(Common _orderTable, SalesUpdate _specQty, CurrencyCode _currencyCode)
    {
        container       resultContainer = conNull();

        resultContainer = next displayFieldsServer(_orderTable, _specQty, _currencyCode);

        if (_orderTable.TableId == tableNum(SalesTable))
        {
            SalesTable  salesTableLoc = _orderTable;
            if (salesTableLoc.HSChangedInD365 == NoYes::No && conPeek(resultContainer, TradeTotals::posTaxTotal()) == 0)
            {
                resultContainer = conPoke(resultContainer, TradeTotals::posTaxTotal(), salesTableLoc.HSTotalWebTaxAmountCur);
                resultContainer = conPoke(resultContainer, TradeTotals::posTotalAmount(), (salesTableLoc.HSTotalWebTaxAmountCur + conpeek(resultContainer, TradeTotals::posTotalAmount())));
            }
        }

        return resultContainer;
    }

Happy DAXING...




No comments:

Post a Comment