web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

(0) ShareShare
ReportReport
Posted on by 45

Dear, 

I have a requirement to add a field that shows the result of Subtract (Subtotal amount - Total discount) in the Totals form in the PurchTotal Group,

Totals form that can be reached by navigating from : 

Accounts Payable -> Purchase Orders -> All Purchase orders 

in the upper menu panel next Delete (Purchase order)  -> View -> Totals 

so what I did is create an extension in my project from the form PurchTotals [Application Suite]  in AOT ->user interface ->forms 

I added a field of type (Real)  in the extension form design and it worked well, but I don't know how to modify the code in the form (PurchTotals.xpp) I get an error message says, cant save ... Unauthorized to modify model 'Application Suite"

I know I need to create an extinction of the class: 

[Form]
public class PurchTotals extends FormRun {

"

but I can not find it anywhere to create an extension of it 

----------------------------------------------------------------------------------------------------------------------------------------

another approach I try to create a copy of the PurchTotals form and I created the new field as real and changed the code in the form class, but now I don't know hot to replace the Totals from "PurchTotals" with the new one "purchTotalsCopy"   

I try to go to Accounts Payable -> Form-> Form setup 

but there is no option to change the PurchTotals form

-----------------------------------------------------------------------------------------------------------------------------------------

another approach I try is to use events that triggers on the current form ,

so I copy the following :

[FormEventHandler(formStr(PurchTotals), FormEventType::Initialized)]
public static void PurchTotals_OnInitialized(xFormRun sender, FormEventArgs e)
{

}

and I created an info message and it showed me the message once I use the form in the upper part of the form,

so I tried to modify the field value but could not hade a way to grab the handler on the form 

PurchTotals purchTotals;
PurchTable purchTable;
container displayFields;
PurchtotalsForm totalsForm;

totalsForm   = PurchtotalsForm::newPurchTotalsForm(purchTable, 1);

but it gives me empty all attributes are NULL when debug 

and it also gives me error message say that the currency is not set i try the code and it did not work :

CurrencyCode accountingCurrency = Ledger::accountingCurrency(CompanyInfo::current());
totalsForm.setCurrencyCode(accountingCurrency);
toCurrencyCode = accountingCurrency;

i don't know what is the approach i need to accomplish that , any suggestion would be appreciated , thank you in advance 

pastedimage1646295563587v1.png

pastedimage1646295579007v2.png

I know I need to add this code in the form code.

pastedimage1646295681875v3.png

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    Hi saffarini,

    You can create a CoC on init method in PurchTotals form and make the changes as you need. You can check this link for details on Chain of command.

    [ExtensionOf(formStr(PurchTotals))]
    final class PurchTotals_Extension
    {
        void  init()
        {
            next init();
            
            Amount_discount.realValue...
        }
    }

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    [ExtensionOf(formStr(PurchTotals))]

    final class PurchTotals_Form_Extension

    {

       private CurrencyCode    toCurrencyCode;

       void  init()

       {

           next init();

           CurrencyCode fromCurrencycode = totalsForm.currencyCodeValue();

           CurrencyExchangeHelper currencyExchangeHelper;

           AmountCur convertAmount(AmountCur _amountCur)

           {

               AmountCur amountCur = _amountCur;

               if (totalsForm.allowEditCurrencyCode() && (toCurrencyCode != fromCurrencycode))

               {

                   if (!currencyExchangeHelper)

                   {

                       currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));

                   }

                   amountCur = currencyExchangeHelper.calculateCurrencyToCurrency(fromCurrencycode, toCurrencyCode, _amountCur, true);

               }

               return amountCur;

           }

           Amount_discount.realValue          (convertAmount(totalsForm.sumLinesValue() + totalsForm.invoiceRoundOffValue() -  totalsForm.endDiscValue() ));

           SumLines_EndDisc.realValue          (convertAmount(totalsForm.sumLinesValue() + totalsForm.invoiceRoundOffValue() -  totalsForm.endDiscValue() ));

       }

    }

    pastedimage1646301772198v1.png

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    pastedimage1646301881192v1.png

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    so using the code on the PurchTotals don't see the added fields,

    using it on the purchTotalsCopy works fine

    any suggestions

  • Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    Amount_discount and SumLines_EndDisc are controls on the form. Correct? Have you set the Auto declaration property to Yes on both these controls?

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    thank you for your previous suggestion, 

    I try this code it doesn't grab the values, any advice, please.

    pastedimage1646307518935v1.png

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    make it static works , i need to grab a handler 

    pastedimage1646308002211v1.png

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    I didn't look at the PurchTotals form before I share the code. I thought you wanted to modify the init method.

    Rather than init method, why don't you create a CoC on "setDisplayFields" method? All the values are being set in this method only. Your code will look like this -

    [ExtensionOf(formStr(PurchTotals))]
    final class PurchTotals_Form_Extension
    {
       private CurrencyCode    toCurrencyCode;
       void  setDisplayFields()
        {
           next setDisplayFields();
           
           CurrencyCode             fromCurrencycode = totalsForm.currencyCodeValue();
           CurrencyExchangeHelper   currencyExchangeHelper;
    
           AmountCur convertAmount(AmountCur _amountCur)
           {
               AmountCur amountCur = _amountCur;
    
               if (totalsForm.allowEditCurrencyCode() && (toCurrencyCode != fromCurrencycode))
               {
                   if (!currencyExchangeHelper)
                   {
                       currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));
                   }
    
                   amountCur = currencyExchangeHelper.calculateCurrencyToCurrency(fromCurrencycode, toCurrencyCode, _amountCur, true);
               }
    
               return amountCur;
           }
    
           Amount_discount.realValue(convertAmount(totalsForm.sumLinesValue()   totalsForm.invoiceRoundOffValue() -  totalsForm.endDiscValue() ));
           SumLines_EndDisc.realValue(convertAmount(totalsForm.sumLinesValue()   totalsForm.invoiceRoundOffValue() -  totalsForm.endDiscValue() ));
       }
    }

  • saffarini Profile Picture
    45 on at
    RE: Form (PurchTotals) and DATA Sources (Common) Customization in Dynamics 365 For Finance and Operations

    works like a charm, I appreciate your swift clear answer, thank you very much

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,157

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 883 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 674 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans