I am currently writing codeunits for Automated Testing in BC. I tried the GenerateRandomCode20 and RandInt from the Codeunit “Library - Utility” and Codeunit “Library - Random”.But when i use them in different function the alwas create the same code what leads to the following error:
The record in table XYZ already exists. Identification fields and values: Packaging Code=‘GU000000060000000000’,Line No.=‘0’
I am calling this function from my own library codeunit various times in one of my test codeunits
procedure CreatePackaging(var Packaging: Record “XYZ Packaging”)
var
begin
Packaging.Init();
Packaging.“Code” := LibraryUtility.GenerateRandomCode20(Packaging.FIELDNO(“Code”), DATABASE::“XYZ Packaging”);
Packaging.Validate(“Packaging Type Code”, CreatePackagingTypeCode());
Packaging.Insert(true);
end;