Access form level selected records from another class on button click

 On Form level we have selected multiple records and we wants to access those selected records on button clicked, the below code can be helpfull.


Created a form : XXXTestForm

Form datasource table : XXXTestTable

Created action menu (Linked class: XXXTestClass) and placed on form action pane : XXXTestMenuItem


Write below code on form button click

[Form]

public class TestTestForm extends FormRun

{

    [Control("MenuFunctionButton")]

    class TestMenuItem

    {

        /// <summary>

        ///

        /// </summary>

        public void clicked()

        {

            super();


            int recordsCount;

            XXXTestTable testTable;

            container con;

            Args args;

            str multiSelectString;

            ;

            args = new Args();

            recordsCount = XXXTestTable_ds.recordsMarked().lastIndex(); // gets the total records selected

            testTable = XXXTestTable_ds.getFirst(1);  // Form Datasource

            while (testTable)

            {

                // storing account num of selected field in container

                con = conIns(con,1,testTable.CustAccount);

                // converting container to string with comma separated

                multiSelectString = con2Str(con,',');


                testTable = XXXTestTable_DS.getNext(); // moves to next record

            }

            // passing string

            args.parm(multiSelectString);

            // calling menu item

            new MenuFunction(identifierstr(XXXTestMenuItem), MenuItemType::Action).run(args);

        }

    }

}

*****************************************************************


Write below code on Class(XXXTestClass), this class linked on action menu item

public class XXXTestClass

{

    public static void main(args _args)

    {

        str multipleRecords;

        ;

        multipleRecords = _args.parm(); 

       Info(strFmt("Form selected values are : %1", multipleRecords));

        }

    }

}


***********************************************************
Output:




Comments

Popular posts from this blog

Execute D365 F&O SSRS report with parameter and upload report output on Azure blob storage using X++

Microsoft D365 F&O: Remove custom models from deployable package

Generate Text/CSV/DAT file using X++ and upload on Azure blob storage