Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Overflow of data in field causing problems

Posted on by 188
Hello!
 
I have a field in the table 336 /Tracking Specification/ that can contain Code[50].
I am currently facing an issue with a big order with a lot of Batch Numbers, and it tries to insert more than the 50 allowed characters in the field, giving an error. The field is standard, so I am not able to modify the length it can take.

This is the field:
 
field(5400; /Lot No./; Code[50])
        {
            Caption = 'Lot No.';
 
            trigger OnValidate()
            begin
                if /Lot No./ <> xRec./Lot No./ then begin
                    TestField(/Quantity Handled (Base)/, 0);
                    TestField(/Appl.-from Item Entry/, 0);
                    if IsReclass() then
                        /New Lot No./ := /Lot No./;
                    WMSManagement.CheckItemTrackingChange(Rec, xRec);
                    InitExpirationDate();
                end;
            end;
        }


Is there any way I can add something to the field to control its length, avoiding an error all together, while also adding the overflow data to another field, which I can then add to the report for show?
Or are there any better ways of controlling the data overflow for such fields?
Categories:
  • Suggested answer
    CU01070638-1 Profile Picture
    CU01070638-1 188 on at
    Overflow of data in field causing problems
    I realized after sitting down and doing some testing that the issue was not the field specifically, but rather a block of code in a custom report that made the issue.
     
    if TempTrackingSpecBufferLotsDict.ContainsKey(TempTrackingSpecBuffer."Item No.") then begin
                            // Add the whole lot text that was registered in OnPreDataItem() for that item number
                            TempTrackingSpecBuffer."Lot No." := TempTrackingSpecBufferLotsDict.Get(TempTrackingSpecBuffer."Item No.");
                        end;
     
    This bit of code inserted every batch number from the lines into the "Lot No." field.
     
    I fixed it by storing the value that would've been inserted in a variable. If the length of the text is longer than 50, I loop through it, find the last ',' before the 50th character, and then split the string, adding the batch numbers before said ',' to the "Lot No." field, and then the rest in an "Additional Lot No." field that I made, that can contain more data.
     
    This is the modified code in my Custom Report:
     
    var
                        LotNoText: Text;
                        MainLotNo: Text;
                        AdditionalLotNo: Text;
                        CommaPos: Integer;
                        i: Integer;
    begin
    if TempTrackingSpecBufferLotsDict.ContainsKey(TempTrackingSpecBuffer."Item No.") then begin
                            LotNoText := TempTrackingSpecBufferLotsDict.Get(TempTrackingSpecBuffer."Item No.");
                            if StrLen(LotNoText) > 50 then begin
                                // Find the last occurrence of ',' before the 50th character
                                CommaPos := 0;
                                for i := 50 downto 1 do begin
                                    if CopyStr(LotNoText, i, 1) = ',' then begin
                                        CommaPos := i;
                                        break;
                                    end;
                                end;
     
                                if CommaPos > 0 then begin
                                    MainLotNo := CopyStr(LotNoText, 1, CommaPos - 1);
                                    AdditionalLotNo := CopyStr(LotNoText, CommaPos + 2);
                                end else begin
                                    MainLotNo := CopyStr(LotNoText, 1, 50);
                                    AdditionalLotNo := CopyStr(LotNoText, 51);
                                end;
     
                                TempTrackingSpecBuffer."Lot No." := MainLotNo;
                                TempTrackingSpecBuffer."Additional Lot No." := AdditionalLotNo;
                            end else
                                TempTrackingSpecBuffer."Lot No." := LotNoText; // Insert the full text if 50 characters or less
                        end;
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,857 Super User on at
    Overflow of data in field causing problems
    Hi, you can split them using some standard string processing methods.
    And Dynamics 365 Business Central: How to split a string into fixed length (Error: The length of the string is xxx, but it must be less than or equal to xxx characters)
     
     
    Thanks.
    ZHU
  • gdrenteria Profile Picture
    gdrenteria 4,883 Super User on at
    Overflow of data in field causing problems
    Hi
    It is possible that this information can give you some hints.
    BR
    GR

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans