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 :
Small and medium business | Business Central, N...
Suggested answer

add a field based on some calculation in query

(0) ShareShare
ReportReport
Posted on by 39

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?
I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,389 on at
    RE: add a field based on some calculation in query

    hi

    look this

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

    DAniele

  • Suggested answer
    DAnny3211 Profile Picture
    11,389 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

  • Muaaz Deyab Profile Picture
    39 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
    Inge M. Bruvik Profile Picture
    1,057 Moderator 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
    39 on at
    RE: add a field based on some calculation in query

    Yes i have tries but it does not work

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sumit Singh Profile Picture

Sumit Singh 2,179

#2
OussamaSabbouh Profile Picture

OussamaSabbouh 1,999

#3
YUN ZHU Profile Picture

YUN ZHU 1,892 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans