Retrieve data from a display method in D365 FO, x++

236 Views Asked by At

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.[![this is the scheme of the form][1]][1] [1]: https://i.stack.imgur.com/YYwrd.png This is my code by now, with all I tried to do:

final class LedgerJournalTransVendInvoice_PostJournal_AzimutBenetti_Extension
{
    public void clicked(){
//    FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
//    FormDataSource formDataSource = formButtonControl.formRun().dataSource(tableStr(LedgerJournalTransVendInvoice));
//LedgerJournalTransVendInvoice ledgerJournalTransVendInvoice = formDataSource.cursor();

FormDataSource ledgerJournalTrans_ds = this.dataSourceObject();
        FormRun formRun = ledgerJournalTrans_ds.cursor().getFormRun();
        str totalAmountSingleLine = formRun.controlCallingMethod('totalAmountSingleLine');

        
    
    if(ledgerJournalTrans_ds.object().totalAmountSingleLine()){
        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();
    }
    
    }
} ```
 
1

There are 1 best solutions below

0
Kraapt On

Honestly I dont understand at all what are you trying to achieve. Subtract two numbers? You can use display method as any other method.

ledgerJournalTrans.totalAmountSingleLine() will return the number. You can then write:

Real result = ledgerJournalTrans.totalAmountSingleLine() - ledgerJournalTrans.RemainingAmount;