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

Notifications

Announcements

No record found.

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,397 on at

    hi

    look this

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

    DAniele

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 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
    Inge M. Bruvik Profile Picture
    1,105 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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans