Monday, November 15, 2021

Add custom dialog form to standard new button in form in d365fo using x++

 Hi guys, I got a requirement like I have to add my custom dialog to the standard New button. I have to change the standard new button operation and I have to add a custom one. Please refer below for the solution.




My custom form


Way 1:

  • In the form design 'Show new button' property I have set it as no. I add a new menu item button in the form and I have called my custom form in that button properties.


Way 2:

  • Override the Create method in the form data source and write the below logic. (Main form). From here we can call our custom form by using args class. Here we have to comment super() otherwise the standard code will run. 
        public void create(boolean _append = false)
        {
            //super(_append); we need to comment super.

            Args            args = new Args();

            args.name(formStr(MyForm));
            args.caller(this);
            args.record(MyTable);

            FormRun myCreateOrder = classfactory.formRunClass(args);

            myCreateOrder.init();
            myCreateOrder.run();

            if  (!myCreateOrder.closed())
            {
                myCreateOrder.wait();
            }

            if  (myCreateOrder.closedOk())
            {
                Info('Clicked ok');
                //MyTable_ds.research(true);
            }
            else
            {
                Info('Clicked cancle');
            }
        }


  • Write the below code in the clicked method of custom form OKCommandButton.

                Mytable      mytable;

        ;

        super();

        if  (MyID.valueStr())
        {
            ttsbegin;
            mytable.clear();
            mytable.MyID = MyID.valueStr();
            mytable.Qty = 1;
            mytable.String = 'Test';
            mytable.InventLocationId = '11';
            mytable.insert();
            ttscommit;

            element.args().record().dataSource().research(true);
        }

  • When I click the new button my custom dialog will open. After entering the my Id and I clicked on the ok button it will insert data in my table and refresh the caller form. 
Keep Daxing!!

No comments:

Post a Comment