In this post I would like to share some useful tips in order to have two different options to quickly change between companies in Business Central.

[EDIT] Since Business Central 22 release, we now have the option to switch companies natively.


At this moment we don´t have an easy and fast access for switching. We need to do 4 ‘clicks’ in order to do so. (Settings + My Settings + Company + Choosing the company) And when your customers have been able to do that with just a keyboard shortcut in older versions of Business Central, right now it can be all the time in the world.

You would think 4 clicks are not a big deal but when the end user has to do it several times a day it really makes it time consuming.

Let´s get started.

[UPDATE] This is a feature that has been released in Business Central. Check it in the following article:


Custom Page in Role Centers

First way is to add a custom company list page and add it to the Role Center.

The key here is using the standard page ‘Allowed Companies’ (9177) and make some changes.

page 50103 "CompanyList"
{
    Caption = 'Companies';
    Editable = false;
    PageType = ListPart;
    SourceTable = Company;
    SourceTableTemporary = true;
    DeleteAllowed = false;
    ModifyAllowed = false;
    InsertAllowed = false;


    layout
    {
        area(content)
        {
            repeater(Group)
            {
                ShowCaption = false;
                field(CompanyDisplayName; CompanyDisplayName)
                {
                    ApplicationArea = All;
                    Caption = 'Name';
                    StyleExpr = NameStyleExpr;
                    ToolTip = 'Specifies the display name that is defined for the company. If a display name is not defined, then the company name is used.';


                    trigger OnAssistEdit()
                    var
                        sessionSetting: SessionSettings;
                    begin
                        sessionSetting.Company := Rec.Name;
                        sessionSetting.RequestSessionUpdate(true);
                    end;
                }
                field("Evaluation Company"; Rec."Evaluation Company")
                {
                    Visible = false;
                    ApplicationArea = All;
                    Caption = 'Evaluation Company';
                    Editable = false;
                    ToolTip = 'Specifies that the company is for trial purposes only, and that a subscription has not been purchased.';
                }
                field(SetupStatus; SetupStatus)
                {
                    Visible = false;
                    ApplicationArea = All;
                    Caption = 'Setup Status';
                    OptionCaption = ' ,Completed,In Progress,Error';
                    ToolTip = 'Specifies the setup status of the company.';


                    trigger OnDrillDown()
                    var
                        AssistedCompanySetupStatus: Record "Assisted Company Setup Status";
                    begin
                        AssistedCompanySetupStatus.DrillDownSetupStatus(Rec.Name);
                    end;
                }
            }
        }
    }


    trigger OnAfterGetCurrRecord()
    var
        CompanyInformationMgt: Codeunit "Company Information Mgt.";
    begin
        CompanyDisplayName := CompanyInformationMgt.GetCompanyDisplayNameDefaulted(Rec);
    end;


    trigger OnAfterGetRecord()
    var
        AssistedCompanySetupStatus: Record "Assisted Company Setup Status";
        CompanyInformationMgt: Codeunit "Company Information Mgt.";
    begin
        CompanyDisplayName := CompanyInformationMgt.GetCompanyDisplayNameDefaulted(Rec);
        SetupStatus := AssistedCompanySetupStatus.GetCompanySetupStatus(Rec.Name);
        if SetupStatus = SetupStatus::"In Progress" then
            NameStyleExpr := 'Subordinate'
        else
            NameStyleExpr := '';
    end;


    trigger OnInit()
    var
        EnvironmentInfo: Codeunit "Environment Information";
    begin
        Initialize();
        SoftwareAsAService := EnvironmentInfo.IsSaaS();
    end;


    var
        CompanyDisplayName: Text[250];
        SoftwareAsAService: Boolean;
        SetupStatus: Option " ",Completed,"In Progress",Error;
        NameStyleExpr: Text;


    procedure Initialize()
    var
        Comp: Record Company;
    begin
        if Comp.FindSet() then
            repeat
                Rec.Init();
                Rec.TransferFields(Comp);
                Rec.Insert();
            until Comp.Next() = 0;
    end;
}

Now we can run it on our Role Center. The tip here is to add a ShortcutKey to access it with no clicks at all. Keep in mind that the Keyboard Shortcut will be available only in the role center page. So if we want to use it we have to be in the Role Center. In this case you only need the shortcut and 1 click!

And if your are not in the Role Center just 2 clicks and the shortcut. 1 for going to the Role Center and the same for the rest.

This option can be access globally. So if you want to access from any other part it will take you 3 clicks to change between companies. In this case it has been reduced by one:

pageextension 50101 "BusinessManagerExt" extends "Business Manager Role Center"
{
    actions
    {
        addlast(SetupAndExtensions)
        {
            action(ChangeCompany2)
            {
                Image = Company;
                Caption = 'Change Company';
                ToolTip = 'Change Company';
                ApplicationArea = All;
                RunObject = Page CompanyList;
                ShortcutKey = 'Ctrl+O';
            }
        }
    }
}

Supplant advanced setting

The advanced settings page can be modified and be replaced with a more useful functionality as it is our custom page. Here is the code:

pageextension 50102 "AdvancedSettingsExt" extends "Advanced Settings"
{
    Caption = 'Change Company';

    layout
    {
        addafter(Header)
        {
            part(CompanySelector; CompanyList)
            {
                ApplicationArea = All;
            }
        }


        modify(BaseAppRow)
        {
            Visible = false;
        }


        modify(ServiceConnectionsGroup)
        {
            Visible = false;
        }


        modify(WorkflowsGroup)
        {
            Visible = false;
        }


        modify(ExtensionsGroup)
        {
            Visible = false;
        }


        modify(ManualSetupGroup)
        {
            Visible = false;
        }
    }
}

Now we can access it also globally and also with just 3 clicks. Here is a quick demo:

Hope you find these tips useful.

Shortcuts For Switching Between Companies In Business Central

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *