Page property of page in Bussiness central cloud

Hi All,

I got a requirement like, client wants Unit Cost and Unit Cost(LCY) visible according to user setup, also 'Unit Price' should be visible and editable according to user setup wise on Sales Order. For it I have created three fields in User Setup table, "Unit Cost Visible", "Unit Price Visible", "Unit Price Editable"

and wrote below code:

pageextension 50007 SOSubFormExt extends "Sales Order Subform"
{
    layout
    {
        modify("Unit Cost (LCY)")
        {
            Visible = UnitCostIsVisible;            
            Editable = false;

        }
        modify("Unit Price")
        {
            Visible = UnitPriceIsVisible;
            Editable = UnitPriceIsEditable;
        }

        modify("Line Amount")
        {
            Visible = UnitPriceIsVisible;
            Editable = UnitPriceIsEditable;
        }


        addafter("Unit Cost (LCY)")
        {
            field("Unit Cost"; "Unit Cost")
            {
                Visible = UnitCostIsVisible;
                Editable = false;
                ApplicationArea = All;

            }
        }

    }
    actions { }
    trigger OnOpenPage()
    var
        myInt: Integer;
    begin
        if UserSetup.Get(UserIdthen begin
            if UserSetup."Unit Cost Visible" = true then begin
                UnitCostIsVisible := true
            end else begin
                UnitCostIsVisible := false;
            end;

            if UserSetup."Unit Price Visible" = false then begin
                UnitPriceIsVisible := false;
                UnitPriceIsEditable := false;
            end else
                if UserSetup."Unit Price Editable" = true then begin
                    UnitPriceIsEditable := true;
                    UnitPriceIsVisible := true;
                end else begin
                    UnitPriceIsVisible := true;
                    UnitPriceIsEditable := false;
                end;
        end;
    end;

    trigger OnAfterGetRecord()
    var
        myInt: Integer;
    begin
        UnitCostIsVisible := false;
        UnitPriceIsVisible := false;
        UnitPriceIsEditable := false;
        if UserSetup.Get(UserIdthen begin
            if UserSetup."Unit Cost Visible" = true then begin
                UnitCostIsVisible := true
            end else begin
                UnitCostIsVisible := false;
            end;

            if UserSetup."Unit Price Visible" = false then begin
                UnitPriceIsVisible := false;
                UnitPriceIsEditable := false;
            end else
                if UserSetup."Unit Price Editable" = true then begin
                    UnitPriceIsEditable := true;
                    UnitPriceIsVisible := true;
                end else begin
                    UnitPriceIsVisible := true;
                    UnitPriceIsEditable := false;
                end;
        end;
    end;


    var
        UserSetup: Record "User Setup";
        UnitPriceIsEditable: Boolean;
        UnitCostIsVisible: Boolean;
        UnitPriceIsVisible: Boolean;
}

It is working fine in Sandbox but in Production even if "Unit Cost Visible" is False still Unit Cost(LCY) is visible on page whare as Unit Cost is not visible.

Where and what I am doing wrong?

Thanks in Advance.

Parents
  • Hi Nikitha,

    If the extension is installed and you do not have any other extensions installed, who could override these settings, then something must be wrong with your code. But reading your code is not easy, you have way to much code. Are you paid by number of lines of code? 

    So I would start by refactoring your code.

    pageextension 50007 SOSubFormExt extends "Sales Order Subform"
    {
        layout
        {
            modify("Unit Cost (LCY)")
            {
                Visible = UnitCostIsVisible;            
                Editable = false;
    
            }
            modify("Unit Price")
            {
                Visible = UnitPriceIsVisible;
                Editable = UnitPriceIsEditable;
            }
    
            modify("Line Amount")
            {
                Visible = UnitPriceIsVisible;
                Editable = UnitPriceIsEditable;
            }
    
    
            addafter("Unit Cost (LCY)")
            {
                field("Unit Cost"; "Unit Cost")
                {
                    Visible = UnitCostIsVisible;
                    Editable = false;
                    ApplicationArea = All;
    
                }
            }
    
        }
        actions { }
    
        trigger OnOpenPage()
        begin
            MyInitPage();
        end;
    
        trigger OnAfterGetRecord()
        begin
            MyInitPage();
        end;
    
        local procedure MyInitPage()
        var
            UserSetup: Record "User Setup";
        begin
            UnitCostIsVisible := false;
            UnitPriceIsVisible := false;
            UnitPriceIsEditable := false;
            
            if UserSetup.Get(UserId) then begin
                UnitCostIsVisible := UserSetup."Unit Cost Visible";
                UnitPriceIsVisible := UserSetup."Unit Price Visible";
                UnitPriceIsEditable := UserSetup."Unit Price Editable";
            end;
        end;
    
        var
            UnitPriceIsEditable: Boolean;
            UnitCostIsVisible: Boolean;
            UnitPriceIsVisible: Boolean;
    }
    

    If this doesn't work, then try to debug your code (not sure if that works in production).

Reply Children
No Data
Related
Recommended