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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

AL code -Custom Field Issue

(0) ShareShare
ReportReport
Posted on by 224
Dear All,
am new to BC and learning from Scratch. i requested all of your support and Help on this always
My Target Req is, Creating 4 Custom Fields and Once User enter the Data then it will ask for the Verification. once user confirm ''yes'' it should be disable particular field  for all the user Except one user. (That User can do the changes if Required)
Now the Issue is,
1st : user will not entering the data altogether , it gets disabling
2nd is : if User enter the  last field then also it disable all the fields
Should disable only the particular field only if user enters the value and once they confirms 
Kindly request all your help to fix the issue

        addafter("Project Manager")
        {
            field("Previous Year Cost"; Rec."Previous Year Cost")
            {
                ApplicationArea = all;
                Editable = IsEditable;
                Caption = 'Previous Year Cost';

                trigger OnValidate()
                var
                    myInt: Integer;
                    Confirm: Label 'You have added a Prev Yr Cost Amount %1 for the Job %2. It should not be editable once confirmed';
                begin
                    If Rec."Previous Year Cost" <> 0.00 then begin
                        If not (UserId = 'ANUSUYA') then begin
                            If Dialog.Confirm(StrSubstNo(Confirm, Rec."Previous Year Cost", Rec."No."), false) then begin
                                CheckEditable();
                                CurrPage.Update();
                            end else
                                Rec."Previous Year Cost" := 0.00;
                        end;
                    end;
                end;
            }

        }
        addafter("Previous Year Cost")
        {
            field("Previous Year Invoice"; Rec."Previous Year Invoice")
            {
                ApplicationArea = all;
                Editable = IsEditable;
                Caption = 'Previous Year Invoice';

                trigger OnValidate()
                var
                    myInt: Integer;
                    Confirm: Label 'You have added a Prev Yr Inv Amount %1 for the Job %2. It should not be editable once confirmed';
                begin
                    If Rec."Previous Year Invoice" <> 0.00 then begin
                        If not (UserId = 'ANUSUYA') then begin
                            If Dialog.Confirm(StrSubstNo(Confirm, Rec."Previous Year Invoice", Rec."No."), false) then begin
                                CheckEditable();
                                CurrPage.Update();
                            end else
                                Rec."Previous Year Invoice" := 0.00;
                        end;
                    end;
                end;
            }

        }
        addafter("Previous Year Invoice")
        {

            field("Project Cost"; Rec."Project Cost")
            {
                ApplicationArea = all;
                Editable = IsEditable;
                Caption = 'Project Revenue';

                trigger OnValidate()
                var
                    myInt: Integer;
                    Confirm: Label 'You have added a Cost Amount %1 for the Job %2. It should not be editable once confirmed';
                begin
                    If Rec."Project Cost" <> 0.00 then begin
                        If not (UserId = 'ANUSUYA') then begin
                            If Dialog.Confirm(StrSubstNo(Confirm, Rec."Project Cost", Rec."No."), false) then begin
                                CheckEditable();
                                CurrPage.Update();
                            end else
                                Rec."Project Cost" := 0.00;
                        end;
                    end;
                end;
            }

        }
        addafter("Project Cost")
        {
            field("Project Expense"; Rec."Project Expense")
            {
                ApplicationArea = all;
                Editable = IsEditable;

                trigger OnValidate()
                var
                    myInt: Integer;
                    Confirm: Label 'You have added a Expense Amount %1 for the Job %2. It should not be editable once confirmed';
                begin
                    If Rec."Project Expense" <> 0.00 then begin
                        If not (UserId = 'ANUSUYA') then begin
                            If Dialog.Confirm(StrSubstNo(Confirm, Rec."Project Expense", Rec."No."), false) then begin
                                CheckEditable();
                                CurrPage.Update();
                            end else
                                Rec."Project Expense" := 0.00;
                        end;
                    end;
                end;
            }

        }

    }

    var
        [InDataset]
        IsEditable: Boolean;

    local procedure CheckEditable()
    var
        UserRec: Record "User Group Member";
    begin
        If Rec."Previous Year Cost" <> 0 then begin
            If UserId = 'ANUSUYA' then
                IsEditable := true
            else
                IsEditable := false;
        end else
            IsEditable := true;

        If Rec."Previous Year Invoice" <> 0 then begin
            If UserId = 'ANUSUYA' then
                IsEditable := true
            else
                IsEditable := false;
        end else
            IsEditable := true;

        If Rec."Project Cost" <> 0 then begin
            If UserId = 'ANUSUYA' then
                IsEditable := true
            else
                IsEditable := false;
        end else
            IsEditable := true;

        If Rec."Project Expense" <> 0 then begin
            If UserId = 'ANUSUYA' then
                IsEditable := true
            else
                IsEditable := false;
        end else
            IsEditable := true;
    end;

    trigger OnAfterGetCurrRecord()
    var
        myInt: Integer;
    begin
        CheckEditable();

    end;

    trigger OnOpenPage()
    var
        myInt: Integer;
    begin
        CheckEditable();
    end;

    trigger OnAfterGetRecord()
    var
        myInt: Integer;
    begin
        CheckEditable();

    end;

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at

    Hi, very interesting. If it were me, I would do the following. I have only done minimal testing, hope this gives you some hints.

    tableextension 50100 CustomerEXT extends Customer
    {
        fields
        {
            field(50101; Field01; Text[50])
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    Verification();
                    CheckUsers();
                end;
            }
            field(50102; Field02; Text[50])
            {
                DataClassification = CustomerContent;
                trigger OnValidate()
                begin
                    Verification();
                    CheckUsers();
                end;
            }
            field(50103; Field03; Text[50])
            {
                DataClassification = CustomerContent;
                trigger OnValidate()
                begin
                    Verification();
                    CheckUsers();
                end;
            }
            field(50104; Field04; Text[50])
            {
                DataClassification = CustomerContent;
                trigger OnValidate()
                begin
                    Verification();
                    CheckUsers();
                end;
            }
            field(50105; FieldsLock; Boolean)
            {
                DataClassification = CustomerContent;
                Editable = false;
            }
            field(50106; FieldsLastModifiedBy; Code[50])
            {
                DataClassification = CustomerContent;
                Editable = false;
            }
        }
    
        local procedure CheckUsers()
        begin
            if UserId <> FieldsLastModifiedBy then
                Error('You can not edit the fields!!!');
        end;
    
        local procedure Verification()
        begin
            if not FieldsLock then
                if Confirm('Confirm ''yes'' it should be disable particular field  for all the user Except you.') then begin
                    FieldsLock := true;
                    FieldsLastModifiedBy := UserId;
                end;
    
        end;
    }
    
    pageextension 50102 CustomerCardExt extends "Customer Card"
    {
        layout
        {
            addafter(Name)
            {
                field(Field01; Rec.Field01)
                {
                    ApplicationArea = All;
                }
                field(Field02; Rec.Field02)
                {
                    ApplicationArea = All;
                }
                field(Field03; Rec.Field03)
                {
                    ApplicationArea = All;
                }
                field(Field04; Rec.Field04)
                {
                    ApplicationArea = All;
                }
            }
        }
    }

    [View:/cfs-file/__key/communityserver-discussions-components-files/758/Test05201002.mp4:1048:786

    Thanks.

    ZHU

  • LearnBC Profile Picture
    224 on at

    Thankyou So Much Zhu for your valuable response. it is highly appreciable and helpful for me in this initial stage for getting this new idea.

    while am testing, the validation/Confirmation Message is asking for only the 1st field only. It should ask for all the fields when the user is entering the data for Each  field.(May b user is not enter all the field at Same time-should Disable only when user enter and give confirmation for each fields)

    and as per my Requirement, Once the data has been enter from End Users side, and confirmation is give Yes, THEN only ADMIN user should only Have the option to Modify that all 4 fields.

  • LearnBC Profile Picture
    224 on at

    Dear Zhu,

    Really thanks for your valuable response and Off course 100 Perc your suggestion is quite simple and highly appreciable

    For identifying Mistakes in My code as a beginner, Could you pls point out/correct  where should i made the mistake in my code also for achieving the desired results also. As a expert it may be a fraction of time only for you to identify the issue. But as a beginner it helps to understand my mistakes also.

     

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans