Dear All,
I have the following code inside a field of Job Tasks subform.
This code is freezing business central and during the debugging is showing out of scope when I hover over the Job.No. I want to read the content of a field from the job table and use it
trigger OnValidate()
var
Job: Record Job;
begin
If "Job Task Type" = "Job Task Type"::Posting then
Job.Reset();
Job.SetRange("No.", "Job No.");
If FindFirst() then
Message('Job is %1 and %2', Job."No.", Job.Description);
End;
What could be the issue with the code and how well can I achieve my goal?
If I remove this piece of code, there is no more freezing, but I need it because I want to pick some details from Job table.
If Rec."Job Task Type" = "Job Task Type"::Posting then
If Job.Get(Rec."Job No.") then begin
Message('Job is %1 and %2', Job."No.", Job.Description);
End;
People Eater,
Contract sum is a field I have customized in the job table.
If I remove modify, BC will not record what I will have entered.
The problem is:
Until Next = 1;
In this example, Are u sure about this line? U said that u just have 1 JOB; so the next line must be 0 but never 1.
Dunno if u understand why its a infinite loop, but its pretty self explanatory why ur program is infinitely looping over it, since u are tellig him to repeat the loop until the next register will be = 1; and there is no other register here.
I am not sure why do you use
Modify(); and Reset();
Also, is it necessary to put calcsum after findset? should it before that?
SetRange("Job Task Type", "Job Task Type"::Posting);
CalcSums("Estimated % Duration Weights"); <---- like this?
Definitely it become slow with CalcFields("Schedule (Total Cost)"); when you have more records.
This is my reading, you can reduce the code by removing unwanted coding, Use separate function, pass the rec, do the calculation, get the value and update.
Hope this will help you.
Hi,
I have tried running your code and it is not freezing at all.. I just wanted to confirm if "Contract Sum" in your code is added by you? because I could not find it in the Job table. Also, please remove "Modify();" from the code
Regards
Nitin Verma,
field("Estimated % Duration Weights"; "Estimated % Duration Weights")
{
ApplicationArea = All;
trigger OnValidate()
var
Job: Record Job;
begin
If Rec."Job Task Type" = "Job Task Type"::Posting then
If Job.Get(Rec."Job No.") then begin
Message('Job is %1 and %2', Job."No.", Job.Description);
End;
If "Job Task Type" = "Job Task Type"::Posting then Begin
Modify();
Reset();
SetCurrentKey("Job No.");
SetRange("Job No.", "Job No.");
SetRange("Job Task Type", "Job Task Type"::Posting);
If Findset() then
Repeat
CalcSums("Estimated % Duration Weights");
CalcFields("Schedule (Total Cost)");
MESSAGE('%1 Weights %2 Budget Cost %3', "Estimated % Duration Weights", "Schedule (Total Cost)", Job."Contract Sum");
If "Estimated % Duration Weights" > 100 then
Error('%1 Weights shouldn''t be greater than 100%!', "Estimated % Duration Weights");
If "Schedule (Total Cost)" > Job."Contract Sum" then
Error('The total lines amount %1 cannot be greater than %2 the contract sum!', "Schedule (Total Cost)", Job."Contract Sum");
Until Next = 1;
CurrPage.Update();
End
else Begin
Error('Percentage Weights can only be applied to Job Tasks of type Posting');
End;
end;
}
Share your complete code once again how you have written your logic
Thanks
I am still experiencing the freezing. I have a trigger on field, Estimated % Duration Weights as shown below encircled in RED. This is a customized field where I put the percentages of Job tasks. All jobs tasks are assigned percentages that don't exceed 100. When I enter 100% since it's one task, BC freezes and I don't get a message as per code that I have shared here.
I really don't know what's causing the freezing. Kindly advice.
As all mentioned you can you GET function instead of setrange and findfirst. GET retrieves one record based on values of the primary key fields.
You can get theoretical idea from here learn.microsoft.com/.../devenv-get-find-and-next-methods
HI,
The problem in your code is, you have not put Begin..End after If condition which is the culprit.
trigger OnValidate() var Job: Record Job; begin If "Job Task Type" = "Job Task Type"::Posting then Begin Job.Reset(); Job.SetRange("No.", "Job No."); If FindFirst() then Message('Job is %1 and %2', Job."No.", Job.Description); end; End;
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,151 Super User 2024 Season 2
Martin Dráb 229,993 Most Valuable Professional
nmaenpaa 101,156