Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

add a field based on some calculation in query

Posted on by 184

I want to calculate the amount in USD (the origin amount / exchange rate if it is LCY) the customer ledger entry and add that to query. I tried to create a procedure in the query to calculate it but how i can add this in the dataitem. This is my code

query 50115 Payments
{
    QueryType = API;
    APIPublisher = 'Muaaz';
    APIGroup = 'Sales';
    APIVersion = 'v2.0';
    EntityName = 'Payments';
    EntitySetName = 'Payments';

    elements
    {
        dataitem(Cust__Ledger_Entry; "Cust. Ledger Entry")
        {
            column(Posting_Date; "Posting Date")
            {
                Caption = 'Posting_Date', Locked = true;
            }
            column(Customer_No_; "Customer No.")
            {
                Caption = 'Customer_No', Locked = true;
            }
            column(Document_Type; "Document Type")
            {
                Caption = 'Document Type', Locked = true;
            }
            column(Amount__LCY_; "Amount (LCY)")
            {
                Caption = 'Payment Amount', Locked = true;
            }
 
           
            d

        }
    }

    local procedure GetAmountUSD(CustLedEntry: Record "Cust. Ledger Entry"): Decimal
    var
        CurrExchangeRate: Record "Currency Exchange Rate";
    begin
        if CustLedEntry."Currency Code" = '' then begin
            CurrExchangeRate.SetRange("Currency Code", 'USD');
            CurrExchangeRate.SetRange("Starting Date", 0D, CustLedEntry."Posting Date");
            if CurrExchangeRate.FindLast() then
                AmountUSD := CustLedEntry."Original Amount" / CurrExchangeRate."Relational Exch. Rate Amount"
            else
                AmountUSD := CustLedEntry."Original Amount";
        end;
    end;

    var
        AmountUSD: Decimal;

}
I can not figure out how to add this variable to the dataitem. Is there anyway i can do this?
  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: add a field based on some calculation in query

    Yes i have tries but it does not work

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: add a field based on some calculation in query

    Did you try to use the procedure as the source for your column?

    column(Amount__USD; GetAmounsUSD(rec))

               {

                   Caption = 'Payment Amount', Locked = true;

               }

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: add a field based on some calculation in query

    I do not think it will work so i created another query for the exchange rate and used it in power PI

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: add a field based on some calculation in query

    hi

    look this

    learn.microsoft.com/.../devenv-triggers

    pastedimage1676114724699v1.png

    queries have only one trigger

    check my answer if it helped you, thanks

    DAniele

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: add a field based on some calculation in query

    hi

    look this

    learn.microsoft.com/.../devenv-onbeforeopen-query-trigger

    DAniele

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans