10 September 2022

Get object of Caller Form In Extension Class/ element to use in init extenion in D365Fo / Is it possible to get element.args() from an extended method in D365FO

Hi, in form method COC we can directly use the this instead of element.Even we can use the control names as it is.
Below is the example.

[ExtensionOf(formstr(ReqTransPO))]
final class ReqTransPOForm_Extension
{
    public void init()
    {
        next init();
        if (this.args().menuItemName() == "ReqPOGridView")
        {
            Contol.visible(false); // form control making visible false
            Control.visible(false);// form control making visible false
        }
    }

}

Get the selected records in the form grid in class 

class ClassParmData

{

         CustTable custTable;// table buffer declaration

}

public static void main(Args args)

{

         ClassParmData parmData;

         Table1 table1;

         FormDataSource fds;

 

         if(args.record().TableId == tablenum(CustTable))

         {

                  custTable = args.record(); // assigning the selected record

         }

 

         fds = custTable.dataSource();// getting the datasource

 

         parmData= new ClassParmData(fds); //passing the form datasource to New() method

}

 

void new(FormDataSource fdst) // receving the datasource to fdst-FormDataSource

{

         // 1st optoin to do this

         MultiSelectionHelper helper = MultiSelectionHelper::construct();

        helper.parmDatasource(fdst);

         custTable = helper.getFirst();

         while (custTable.RecId != 0)

        {

                  custTable = helper.getNext();

         }

         // second way

         for(custTable = fdst.getFirst(true); custTable; custTable = fdst.getNext()) // fdst.getFirst(True) to select marked records

         {

                  info(strfmt(custTable.Field1));

         }

         //if you are updating some records in the form write the below line to refresh the data in form.

         //fdst.research();

}

 

void parmFormDataSource(formDataSource fdst)

{

         for(custTable = fdst.getFirst(true); custTable; custTable = fdst.getNext()) // fdst.getFirst(True) to select marked records

         {

         info(strfmt(custTable.Field1));

         }

         //if you are updating some records in the form write the below line to refresh the data in form.

         //fdst.research();

}

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...