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 :
Business Central forum
Under review by Community Managers

Under review

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

Issues in AL Code

Posted on by 213

Hello All,

am new to BC and its my learning Stage. i request the kind help and considerations from the Experts

i created 4 custom fields, and once User is entered the data then it should disabled and Should be editable to one particular user only,

1st issue -  allowing only to enter all the data together otherwise it get disabling. (It should not be like that, it should disable only which field is user confirming

2nd  - if user enters last field 1st , it get disabling all the fields. it should separate for each fields

Kindly correct where i made the mistake in Code.


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;

Code.txt

Kindly correct where i made the mistake in Code.

Regards

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans