Dynamic Visibility of Controls Company Specific (Hide and show fields dynamically)

Suppose you have a requirement to show a field in some companies and hide it in others. 

First Read this Visible Property

For example, I have added a 'Lease' section to the Sales Order page, which contains three fields: Lease Status, Lease Amount, and RKD Proyecto. The visibility of this section is controlled by the isVisible variable, which is set within the CompanySpecificVisibility procedure. This procedure checks the company name from the Company Information. Based on the company name, we handle visibility by setting isVisible to true for 'CRONUS IN', and false for 'My Company' and 'My Company US'. The visibility logic is executed when the page opens, using the OnOpenPage trigger.

So, when the user opens the Sales Order page:

If the company is 'CRONUS IN', the 'Lease' section is visible.


If the company is 'My Company' or 'My Company US', the 'Lease' section is hidden.



Code:

pageextension 50704 "Sales Order Ext" extends "Sales Order"
{
    layout
    {
        addafter(General)
        {
            group("Lease")
            {
                ShowCaption = false;
                Visible = isVisible;

                field("Lease Status"; Rec."Lease Status")
                {
                    ApplicationArea = All;
                    Caption = 'Lease Status';
                }

                field("Lease Amount"; Rec."Lease Amount")
                {
                    ApplicationArea = All;
                    Caption = 'Lease Amount';
                }
                field("RKD Proyecto"; Rec."RKD Proyecto")
                {
                    ApplicationArea = All;
                    Caption = 'RKD Proyecto';
                }
            }
        }
    }
    trigger OnOpenPage()
    begin
        CompanySpecificVisibility();
    end;

    local procedure CompanySpecificVisibility()
    var
        companyinformation: Record "Company Information";
    begin
        if companyInformation.Get() then
            case companyinformation.Name of
                'CRONUS IN': 
                    isVisible := true;
                'My Company':
                    isVisible := false;
                'My Company US':
                    isVisible := false;
            end;
    end;

    var
        isVisible: Boolean;
}

Hope this helps..!!

Regards,
Khushbu Rajvi

Comments