web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Add controls run time and override the method in D356 (X++)

Ajit Profile Picture Ajit 8,755
Here I will be explaining, how to create buttons run time and override the clicked method.

We would be creating buttons run time based on the setup companies in some custom table, Like I have table called 'DemoCompanyList' and that table has 3 companies setup

1. USMF
2. USMG
3. IND

Lets create a form and give a name 'DemoRunTimeControl' and then we can apply the pattern based on our requirement and then add Action Pane - Button Group - Menu Button(control name - ButtonHeaderInquiry), change the AutoDeclaration property to 'Yes' for this control.

Form Methods - 


init() - To get the list of companies and call method addRunTimeButtons()

addRunTimeButton() - In this method we will add buttons to menu button and also register the clicked method so that when we click on those buttons, it should the written clicked method.

RunTimeButton_clicked() - In this method we will opening the custInvoiceJour menu item based on the clicked button.


[Form]
public class DemoRunTimeControl extends FormRun
{
    Map                 buttonCompany;
   
    public void init()
    {
        container   companies;
        counter     i;

        super();

        buttonCompany = new Map(Types::Integer, Types::String);

        companies = DemoCompanyList::findCompanyList(); // Find company list will return the list of the companies

        for (i = 1; i <= conLen(companies); i++)
        {
            element.addRunTimeButton(conPeek(companies, i)); //addRunTimeButtons will add buttons based on the company setup
        }
    }

    private void addRunTimeButtons(DataAreaId _dataAreaId = #emptyString)
    {
        FormButtonControl           runTimeControl;
        #define.runTimeCtrl         ('DemoRunTimeButton')

        runTimeControl = ButtonHeaderInquiry.addControl(FormControlType::Button, #runTimeCtrl + _dataAreaId);
        //Invoice (%1)
        runTimeControl.text(strfmt("Customer Invoice (%1)", _dataAreaId));
        runTimeControl.registerOverrideMethod(methodStr(FormButtonControl, clicked), formMethodStr(DemoRunTimeControl, 'RunTimeButton_clicked'), element);
        buttonCompany.insert(runTimeControl.id(), _dataAreaId);
    }

    public void RunTimeButton_clicked(FormButtonControl _formButtonControl)
    {
        //Set the local control to the actual control that is calling the method.
        _formButtonControl = this.controlCallingMethod();
        CompanyId company;

        company = buttonCompany.lookup(_formButtonControl.id());

        if (company)
        {
            changecompany (company)
            {
                //Open invoice journal in specific company
                new MenuFunction(MenuItemDisplayStr(CustInvoiceJour),MenuItemType::Display).run();
            }
        }

    }

}



When you will click on first button, system will open customer invoice journals form in USMF company and the same way if you click on IND one, system will open journals from IND company.





Comments

*This post is locked for comments