Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Retrieve value of a field given by a display method

Posted on by 71
Hi everyone, I'm new in d365 and I'm having some issues with my task because of a display method.
I am in the form LedgerJournalTransVendInvoice, where I have the field 'Total Amount'. Cheking the properties of the field I can see it's a calculated field connected to the method totalAmountSingleLine. This method is a display method in the DataSource of my form, and of course the display method in the end returns the TotalAmount that I need in my project in order to confront it with another field called RemainingAmount. Any suggestion on how can I do it? I tried several ways but nothing seems to work properly.
  • FabFab97 Profile Picture
    FabFab97 71 on at
    Retrieve value of a field given by a display method
    Thank you all for your suggestions, I tried everyithing you wrote but nothing seems to work. It's like the class of the form is invisible to my module. so It gives me error anytime I call LedgerJournalTransVendInvoice. I tried with other forms and tables and i manage to get the methods i wanted to, but not in this one
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,332 Super User 2024 Season 2 on at
    Retrieve value of a field given by a display method
    Hi @ Fabrizio,
     
    You can try this code but make sure to change your display method to have the table record as a parameter.
     
    [ExtensionOf(formDataSource(LedgerJournalTransVendInvoice, LedgerJournalTrans))]
    final class LedgerJournalTransVendInvoiceFormDS_Extension
    {
     display Amount totalAmountSingleLine(LedgerJournalTrans _ledgerJournalTrans)
    {
        Amount yourAmount;
       // your logic
        return yourAmount;
    }
    }
    [ExtensionOf(formControlStr(LedgerJournalTransVendInvoice, PostJournal))]
    final class LedgerJournalTransVendInvoice_PostJournal_AzimutBenetti_Extension
    {
      
        public void clicked()
        {
    
            IntentLetter_IT intentLetter;
    
            FormDataSource ledgerJournalTrans_ds = this.formRun().dataSource(tableStr(LedgerJournalTrans));
            LedgerJournalTrans ledgerJournalTrans = ledgerJournalTrans_ds.cursor();
            
            if(ledgerJournalTrans_ds.totalAmountSingleLine(ledgerJournalTrans) > intentLetter.remainAmountMST())
            {
                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
                        );
            }
            next clicked();
    
        }
    
    }
     
    Regards
    Waed Ayyad
     
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Retrieve value of a field given by a display method
    Hi Farbizio,


    I think you need to use "Object" -- I'm not sure if this will work, but maybe give the below code a try: (i amended your code alittle)
     
    [ExtensionOf(formControlStr(LedgerJournalTransVendInvoice, PostJournal))]
    final class LedgerJournalTransVendInvoice_PostJournal_AzimutBenetti_Extension
    {
      
        public void clicked()
        {
    
            IntentLetter_IT intentLetter;
    
            FormDataSource ledgerJournalTrans_ds = this.formRun().dataSource(tableStr(LedgerJournalTrans));
            LedgerJournalTrans ledgerJournalTrans = ledgerJournalTrans_ds.cursor();
    
            Object dataSourceObject = ledgerJournalTrans_ds;
            
            if(dataSourceObject.totalAmountSingleLine(ledgerJournalTrans) > intentLetter.remainAmountMST())
            {
                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
                        );
            }
            next clicked();
    
        }
    
    }

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Anthony Blake Profile Picture
    Anthony Blake 2,184 Super User 2024 Season 2 on at
    Retrieve value of a field given by a display method
    Buffers are a whole other subject to the error you have posted.
     
    High level - its a structure to hold an object representing a table row.
     
    There's loads of reading (and practising!) to do to understand, have a read and create some runnable classes to try things out.
     
    Example of X++ buffers, first result of a popular search engine https://supremexpp.wordpress.com/2018/12/13/x-pitfalls-lesson-1-table-buffers/
  • FabFab97 Profile Picture
    FabFab97 71 on at
    Retrieve value of a field given by a display method
    Thank you,
    Sorry but I've never used or heard about buffers in D365, can u tell me where can I find it?
    I'm also trying to use an Event Handler OnModified in order to  get the value of the field, but I can't do it neither
  • Suggested answer
    Anthony Blake Profile Picture
    Anthony Blake 2,184 Super User 2024 Season 2 on at
    Retrieve value of a field given by a display method
    in this line:
     
     
    if(ledgerJournalTrans_ds.totalAmountSingleLine() > intentLetter.remainAmountMST()){
     
     
    you need to pass a buffer of type LedgerJournalTrans to your display method, this is always the case for form data source display methods, see the definition here:
     
    display Amount totalAmountSingleLine(LedgerJournalTrans _ledgerJournalTrans)
     
    in here you need the record buffer:
     
    if(ledgerJournalTrans_ds.totalAmountSingleLine(ledgerJournalTransBufferGoesHere) > intentLetter.remainAmountMST()){
     
  • FabFab97 Profile Picture
    FabFab97 71 on at
    Retrieve value of a field given by a display method
    if it can be helpful in any way, I'll post here also the content of the display method: 
    [Form]
    public class LedgerJournalTransVendInvoice extends FormRun implements TaxIFormShowTax, IFormRefreshable, LedgerILedgerJournalEngineProvider, LedgerIJournalFormRefreshable, LedgerIJournalFormCache, LedgerIJournalCashDiscount, OfficeIMenuCustomizer, OfficeITemplateCustomExporter, LedgerIJournalForm
    {
    [DataSource]
        class LedgerJournalTrans
        {display Amount totalAmountSingleLine(LedgerJournalTrans _ledgerJournalTrans)
            {
                TaxAmountCur signedActualTax;
                Amount totalAmount, taxAmount, transactionAmount;
                transactionAmount = _ledgerJournalTrans.amount();
    
                if (TaxSolutionScopeIntegrationUtil::isCompanyEnabled())
                {
                    TransTaxInformation transTaxInformationLoc = TransTaxInformationHelper::findOrCreateTransTaxInformationByRecord(_ledgerJournalTrans);
                    if (transTaxInformationLoc && !transTaxInformationLoc.InclTax)
                    {
                        ITaxDocument taxDocument = TaxBusinessService::calculateTax(TaxableDocumentObject::construct(TaxableDocumentDescriptorFactory::getTaxableDocumentDescriptor(_ledgerJournalTrans)));
    
                        if (taxDocument)
                        {
                            ITaxDocumentLine taxDocumentLine = taxDocument.findLineBySource(_ledgerJournalTrans.TableId, _ledgerJournalTrans.RecId);
    
                            if (taxDocumentLine)
                            {
                                taxAmount = abs(taxDocumentLine.getLineTax().amountTransactionCurrency());
                            }
                        }
                    }
                }
                else if (!ledgerJournalTable.LedgerJournalInclTax)
                {
                    if (_ledgerJournalTrans.TaxCode)
                    {
                        return transactionAmount;
                    }
    
                    LedgerJournalEngine ledgerJournalEngineVendInvoice = LedgerJournalEngine::construct(ledgerJournalTable.JournalType);
                    ledgerJournalEngineVendInvoice.ledgerJournalTable(ledgerJournalTable);
                    taxAmount = ledgerJournalEngineVendInvoice.correctedTaxAmount(_ledgerJournalTrans);
    
                    if (_ledgerJournalTrans.TaxGroup
                        && _ledgerJournalTrans.TaxItemGroup
                        && _ledgerJournalTrans.AccountType == LedgerJournalACType::Vend)
                    {
                        signedActualTax = ledgerJournalEngineVendInvoice.parmActualTax();
                        if ((transactionAmount > 0 && signedActualTax > 0) || (transactionAmount < 0 && signedActualTax < 0))
                        {
                            taxAmount = -taxAmount;
                        }
                    }
                }
    
                if (transactionAmount > 0)
                {
                    totalAmount = transactionAmount + taxAmount;
                }
                else
                {
                    totalAmount = transactionAmount - taxAmount;
                }
    
                return totalAmount;
            }
    }
    }
    Of course the entire code is much bigger with lots of more methods, but I don't think the rest is important for my issue, here you can see the form, the datasource and the display method, as displayed in the image on my first answer
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    Retrieve value of a field given by a display method
    If you want to use a display method, then you need to recreate same SQL statement like a view or if you are using it in any data entity then you have to use computed columns. Please tell us complete requirement.
  • FabFab97 Profile Picture
    FabFab97 71 on at
    Retrieve value of a field given by a display method
    Hi @Layan Jwei,
     
    Sure, sorry if I haven't been clear. In my project I need to display a pop up when, posting a new journal, the TotalAmount of that specific journal is higher of the RemainingAmount of the specified client, as reported on the intent letter. For example If the remaining amount on the intent letter of a client is 100 and I'm posting a journal with a total amount of 1000, it should stop the registration of the journal and the pop up alert should appear. The remaining amount is on the intent letters form, and is a normal field of the intent letters table, while the Total Amount is a calculated field given by the method totalAmountSingleLine found on the form datasource, I can see its code if I look on the class of the form at least, and it's a display method. This is the code I wrote by now, looking on internet for a solution to my problem:
    [ExtensionOf(formControlStr(LedgerJournalTransVendInvoice, PostJournal))]
    final class LedgerJournalTransVendInvoice_PostJournal_AzimutBenetti_Extension
    {   
      
        public void clicked(){
    
                IntentLetter_IT intentLetter;
    
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
            FormDataSource formDataSource = formButtonControl.formRun().dataSource(tableStr(LedgerJournalTrans));
            LedgerJournalTrans ledgerJournalTrans_ds = formDataSource.cursor();
         
            if(ledgerJournalTrans_ds.totalAmountSingleLine() > intentLetter.remainAmountMST()){
                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
                        );
                next clicked();
            }
        }
    and I keep getting this error:  Error        ClassDoesNotContainMethod: Table 'LedgerJournalTrans' does not contain a definition for method 'totalAmountSingleLine' and no extension method 'totalAmountSingleLine' accepting a first argument of type 'LedgerJournalTrans' is found on any extension class.    
    I hope it's more clear now, 
    Thank You.
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Retrieve value of a field given by a display method
    Hi Fabrizio,

    can you please explain more what do you need to do with RemainingAmount and TotalAmount? and show us please the code that you tried so that we can understand what are you trying to do.

    Thanks,
    Layan Jweihan

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans