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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Confront Data from different Tables

(0) ShareShare
ReportReport
Posted on by 71
Hi everyone, I am trying to learn D365 Fo and I'm having some issues at the begininng, wich I think are very basic. 
In this case I'm creating a new Journal from the Table VendInvoiceInfoLine. In this table I have a lookup field where i select the Intent Letter that receives the request, and another field with the Total Amount of the Journal. Then I have the table IntentLetter where are stored all the intent letter and they have a field called RemainingAmount. I need to compare the Total Amount of the Journal with the Remaining Amount of the intent letter, and check if the first one is lower than the second in order to proceed with the registration of the Journal. I think I need to use the While select statement to access the right data, maybe using RecId and a join, but I really don't know how to proceed and what's the right way to do it. Can anyone help? Thank you very much!
  • André Arnaud de Calavon Profile Picture
    307,719 Super User 2026 Season 2 on at
    Hi Fabrizio,

    I have only seen an Italian localization feature for intent letters on the customer invoices part. I'm not familiar with this feature and don't know if it is available on vendor invoices in the standard application.

    Can you explain the required process from a functional point of view? You are talking about the creation of a journal from VendInvoiceInfoLine. What exact steps do you take here? Where and how are intent letters entered? 
     
  • FabFab97 Profile Picture
    71 on at
    Hi Andre, I'll try to be more clear.
    I think that for what concerns intent letters table is all clear. 
    In order to create a journal I go to Accounts Payable > all supplier orders > New, i choose an account. I get redirected into a table where i can define the lines and the heading, if i go to heading and then scroll down to Settings i can choose, with a lookup, an Intent Letter for my journal. It's a long process until I can finally post my journal, but this is where i select the Intent Letter i want to bound to my journal. If I right click on the lookup I can see that it belongs to the purchTable and the field is called IntentLetterId_IT. 
    if I go on, i find the Button POST in the VendEditInvoice form, and once i click on it, the code must check if the amount of the journal I'm trying to post is bigger than the remaining amount on the intent letter, if so, a pop up should appear. My problem is only about accessing the data that I need, so the totalAmount, that is found in VendEditInvoice.LineAmount and the intent letter i choose, that is found in intentLetter.remainAmount(), but I don't know how to. I tried with a while select but I don't think that a loop is really useful to me now, i just need 2 values to confront. I hope it is more clear now.
    Thank you very much btw!
  • André Arnaud de Calavon Profile Picture
    307,719 Super User 2026 Season 2 on at
    Hi Fabrizio,
     
    I'm still not fully aware of your needs. Maybe it will help me understanding if you share the coding you have build so far. Then we can check if and how it would be possible to bypass a while select
  • FabFab97 Profile Picture
    71 on at
    This is my code: 
    [ExtensionOf(formStr(VendEditInvoice))]
    final class VendEditInvoice_AzimutBenetti_Extension
    {
    
        protected boolean canProceedWithInvoicePosting()
        {
            boolean ret = next canProceedWithInvoicePosting();
            
            if (!this.validateIntentLetter())
            {
                ret = false;
            }
           
            return ret;
        }
    
        //public void clicked()
        //{
        //    boolean proceed = this.validateIntentLetter();
    
    
        //    if (proceed)
        //    {
    
        //       super();
        //    }
    
    
        //}
    
        // A new method for your validation logic
        private boolean validateIntentLetter()
        {
            VendInvoiceInfoLine vendInvoiceInfoLine; // Ottieni la fattura corrente
            PurchTable purchTable;
            
            Amount totalAmount = vendInvoiceInfoLine.LineAmount;
    
            // Ottenere l'ID della lettera di intento dalla tabella di lookup
            
                IntentLetter_IT intentLetter;
    
                // Recuperare la lettera di intento associata all'ID
                select firstOnly intentLetter
                    join purchTable
                    where intentLetter.IntentLetterId == purchTable.IntentLetterId_IT;
    
                // Ottenere l'ID della lettera di intento
                Amount remainingAmount = intentLetter.remainAmountMST();
    
                Info(strFmt('%1, %2', totalAmount, remainingAmount));
    
                if (totalAmount >= remainingAmount)
                {
                    DialogButton diagBut;
                    str strMessage = "Importo da decurtare al saldo della lettera di intento maggiore dell’importo residuo. Proseguire?";
                    str strTitle = "Splafonamento";
                    diagBut = Box::yesNo(
                        strMessage,
                        DialogButton::No,
                        strTitle
                    );
                    if (diagBut == DialogButton::No)
                    {
                        info('Operazione annullata');
                        return false;
                    }
                   
                }
            
    
            return true;
        }
    
    }
    When I click on the Post Button, in VendEditInvoice, if the TotalAmount of the journal is bigger than the RemainAmount on the Intent Letter, the pop up appear. I can't retrieve Data from the current journal, so from VendEditInvoice.LineAmount, and the data from the Intent letter i select from a lookup in the form VendEditInvoice, the lookup is in the Table purchTable.
    I hope it's more clear now
  • Martin Dráb Profile Picture
    241,360 Most Valuable Professional on at
    You still haven't fixed the bug I told you about last week in your other thread.
     
    You never assign any value to vendInvoiceInfoLine variable, therefore totalAmount will always be zero.
     
    Also, you select the first record in intentLetter, with no relation to the currently processed invoice
     
    You would easily find these bugs on your own if you walked through your code in debugger. Not using a debugger is a big mistake; it's a part of the reason why you're unable to implement what you want.
  • FabFab97 Profile Picture
    71 on at
    Yes i did debug the project and I see that there is no data, but I still don't know how to fix that
  • Martin Dráb Profile Picture
    241,360 Most Valuable Professional on at
    I suggest you start with the bugs I told you about. First thing first, you'll need to set a value of totalAmount.
     
    Your idea is getting the total amount from a single invoice line, but does it really makes sense? Shouldn't you summarize amounts of all lines of a given invoice?
  • FabFab97 Profile Picture
    71 on at
    The fact is that I don't need to calculate the TotalAmount, When I select a product for the journal I already have, based on the quantity I choose and the taxes, the line with the total amxount. I just need to access to that data. 
     This is the Lookup where I choose my IntentLetter.
     These are the info about the lookup's module.
     this is the Total Amount I need, or maybe it's better to call it NetAmount or LineAmount
     And these are the info about the LineAmount 
  • Martin Dráb Profile Picture
    241,360 Most Valuable Professional on at
    That's an amount of a single line, isn't it? It's equal to the total amount in just one case: when there is just a single line. If there are more lines, no single line give you the right values, because you need to put together amounts of all lines. Don't you agree?

    For example, which one of these lines gives you the total amount?


    None - the total is neither 100 nor 50. It's 150.
  • FabFab97 Profile Picture
    71 on at
    Yeah sure, but I think that what i need is to post a journal for every single line. So I'll need to post one of 100 and one of 50 based on your example. But it would be useful also to know how to make the sum I think, because all I get by now is 0

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 543 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 415 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 188

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans