Add form controls without form modification

Hi! Sometimes Customer requires that developed solution doesn’t touch the standard forms, because Customer wants minimize the merge process. If you should add some controls to the form without form modification than this topic could help you.

Let’s assume that CustInvoiceJournal and CustConfirmJournal forms should have new menu button with menu item.

  1. Create the static method:
    static void addMenuItems(formRun _caller)
    {
    FormFunctionButtonControl formFunctionButtonControl;
    FormButtonGroupControl formButtonGroupControl;
    FormMenuButtonControl formMenuButtonControl;
    ;

    switch (_caller.name())
    {

    case formstr(CustInvoiceJournal) :
    formButtonGroupControl = _caller.form().design().control(identifierstr(OverviewButtonGroup));
    break;

    case formstr(CustConfirmJournal) :
    formButtonGroupControl = _caller.form().design().control(identifierstr(ButtonGroupOverview));
    break;

    case formstr(CustPackingSlipJournal) :
    formButtonGroupControl = _caller.form().design().control(identifierstr(OverviewButtonGroup));
    break;

    }

    if (formButtonGroupControl)
    {
    // new menu button
    formMenuButtonControl = formButtonGroupControl.addControl(FormControlType::MenuButton, identifierstr(NameOf_MenuButton));
    formMenuButtonControl.text('New menu button');

    //new menu item
    formFunctionButtonControl = FormMenuButtonControl.addControl(FormControlType::MenuFunctionButton, identifierstr(NameOf_MenuItem));
    formFunctionButtonControl.menuItemType(MenuItemType::Display);
    formFunctionButtonControl.menuItemName(MenuItemDisplayStr(CustTable));
    }
    }

  2. Add the following code to the SysSetupFormRun.init method:
    public void init()
    {
    ;

    Class1::addMenuItems(this);//New code

    super();

    SysSecurityFormSetup::loadSecurity(this);
    this.dimensionFieldCtrls();
    this.inventStorageDimFieldCtrls();

    if (this.isWorkflowEnabled())
    {
    workflowControls = SysWorkflowFormControls::construct(this);
    workflowControls.initControls();
    }
    }

    This is all.

Sometimes it is required to change form behavior without form modification. Let’s assume when User clicks the Preview/Print button on the CustInvoiceJournal form the info message shows.

  1.  Add the following code the the SysSetupFormRun.init method:
    public void init()
    {
    ;
    super();

    SysSecurityFormSetup::loadSecurity(this);
    this.dimensionFieldCtrls();
    this.inventStorageDimFieldCtrls();

    if (this.isWorkflowEnabled())
    {
    workflowControls = SysWorkflowFormControls::construct(this);
    workflowControls.initControls();
    }

    if (Class1::overload(this)) // new code
    { // new code
    this.controlMethodOverload(true); // new code
    this.controlMethodOverloadObject(new Class1(this)); // new code
    }
    }

  2. The Class1 class has the following methods:
    void new(FormRun _caller)
    {
    ;
    caller = _caller;
    }
    public static boolean overload(FormRun _caller)
    {
    ;
    switch (_caller.name())
    {
    case formstr(CustInvoiceJournal):
    return true;
    }

    return false;
    }

    To override method behavior the class method should have the following name: ControlName_methodName(). In our case we override the clicked() method of the SalesInvoiceShow control:
    void SalesInvoiceShow_clicked()
    {
    CustInvoiceJour custInvoiceJour;
    FormDataSource formDataSource;
    FormButtonControl buttonControl;
    ;

    formDataSource = caller.dataSource();
    custInvoiceJour = caller.dataSource().cursor();

    if (custInvoiceJour.InvoiceId != "11111111")
    {
    info("You can't open invoice preview because we override button behaviour");
    }
    else//call super()
    {
    buttonControl = caller.controlCallingMethod();
    buttonControl.clicked();
    }
    }

    That is all. If we open the CustInvoiceJournal and click the Preview/Print the info message will be shown. If Invoice id is 11111111 then button will have the standard behaviour (i.e. the Invoice will be shown)

All the best 😉