Friday, 4 December 2020

Open the Journal lines form in D365FO with Jumpref

 Requirement: To open Journal lines form by clicking on view details of the filed on the form.


Development:

1. RegisterOverride the jump ref method on a form

[ExtensionOf(formStr(ProjInvoiceProposalDetail))]

final class ProjInvoiceProposalDetailFormBKA_Extension

{

    public void init()

    {

        next init();


        //ProjProposalCost_BKATrackingID is control name on form

        ProjProposalCost_BKATrackingID.registerOverrideMethod(

                methodStr(FormStringControl, jumpRef),

                methodStr(ProjInvoiceProposalDetailFormBKA_Extension, bkaTrackingIdJumpRef),

                this);

    }


    private void akaTrackingIdJumpRef(FormStringControl _formStringControl)

    {

        VendInvoiceJour::BKATrackingIDJumpRef(ProjProposalCost.BKATrackingId);

        _formStringControl.jumpRef();

    }

}


//I have centralized the jumpref's method on a table

//Opening the journal lines form is bit tricky, so below is the code will work

[ExtensionOf(tableStr(VendInvoiceJour))]

final class VendInvoiceJourBKA_Extension

{

 static void BKATrackingIDJumpRef(BKATrackingID _trackingId)

    {

        Args                        args, transArgs;

        FormRun                     formRun, transFormRun;

        JournalFormTable            journalForm;

        LedgerJournalTrans          ledgerJournalTrans;

        LedgerJournalTable          ledgerJournaltable;

        MenuFunction                menuFunction;

        ;

        


        changecompany (_trackingIdCompany)

        {

            //todo: change code for tracking Id

            select firstonly ledgerJournalTrans

               where ledgerJournalTrans.Voucher == _trackingId;


            ledgerJournaltable = LedgerJournalTable::find(ledgerJournaltrans.JournalNum);

        }


        //Open form

        args = new Args();

        args.name(formStr(LedgerJournalTable));

        args.record(ledgerJournaltable);


        formRun = classfactory.formRunClass(args);

        formRun.init();

        LedgerJournalFormTable journalFormTable = formRun.journalForm();

        journalFormTable.journalTableData(JournalTableData::newTable(ledgerJournalTable));


        transArgs = new Args();

        transArgs.caller(formRun);


        if (ledgerJournaltable.JournalType == LedgerJournalType::Daily)

        {

            transArgs.name(formStr(LedgerJournalTransDaily));

        }

        else if (ledgerJournaltable.JournalType == LedgerJournalType::VendInvoiceRegister)

        {

            transArgs.name(formStr(LedgerJournalTransVendInvoice));

        }

        transArgs.record(ledgerJournaltable);


        transFormRun  = classfactory.formRunClass(transArgs);

        transFormRun.init();

        transFormRun.run();

}

}