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

Announcements

No record found.

News and Announcements icon
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,421 Super User 2026 Season 1 on at

    hi

    look this

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

    DAniele

  • Suggested answer
    DAnny3211 Profile Picture
    11,421 Super User 2026 Season 1 on at

    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

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

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,177 Moderator on at

    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

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,892 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 927 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 566 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans