Skip to main content

Notifications

Announcements

No record found.

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

add a field based on some calculation in query

(0) ShareShare
ReportReport
Posted on by 29

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 29 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 993 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 29 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,274 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,274 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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans