For some background, I'm a junior Business Central AL developer with not much experience. I am hoping to find some help with the syntax of what I'm trying to accomplish.
Situation:
I have several Sales Lines displaying in a Sales Order. I want to increase the width of the Sales Line "No." field based on the longest "No." value.
Example:
Sales Order abc123 has four Sales Line entries:
- Sales Line 1. "No." 123
- Sales Line 2. "No." 1234
- Sales Line 3. "No." 12345
- Sales Line 4. "No." 1234567
Desired outcome of example:
The "No." column of the Sales Line to have its width property set to the length of the longest "Sales Line"."No.". In this example, the width property would be set to 7 (Longest sales line is #4, with a length of 7).
What I have so far:
I have the following psuedo(ish)code and I'm not really sure how to put it into practice. The specific part I'm struggling with is inserting each "Sales Line"."No." length ("No.".StrLen(String: Text)) into the array (SalesLineNumbers), and then finding the largest integer in the array.
modify("No.") {
trigger OnAfterValidate();
var
SalesLineNumbers: array of Integer;
MaxSalesLineNumberLen: Integer;
begin
"Sales Header".Get(abc123); //find the sales header we are working with
foreach "Sales Line"."No." in "Sales Header": //perform the following actions for each sales line within this sales header
insert into SalesLineNumbers "No.".StrLen(String: Text); //add the length of the "Sales Line"."No." into the array
MaxSalesLineNumberLen := max(value in SalesLineNumbers); //set MaxSalesLineNumberLen to the largest integer in the array
end;
Width = MaxPartNoLen; //set the width property of field "No." to MaxPartNoLen
}
If there is any more information you need me to provide, or if I'm not clear in what I'm trying to accomplish, please let me know.
Thank you in advance for reading.
