It would be VERY useful if we had a slightly more flexible way of building in memory data,
Temporary tables can be OK but aren't that flexible for complex data structures and can be awkward/unpredictable when passing them around.
Json Objects/Arrays are fine but lack design time specificity and a strong type system can make code hard to follow and ease of extensibility suffers.
Dictionaries just aren't quite flexible enough for more than the simplest of requirements
A Struct (or Tuple?) like object would allow much greater freedom, for example
Struct ComplexEntity
{
field(SourceRecord; Recordid);
field(RelatedRecords; List of [RecordId]);
field(ProcessType; enum "My Process Type Enum");
}
codeunit 50000 "My Codeunit"
{
procedure GetRecords() Result: List of [Struct ComplexEntity];
var
MyComplexEntiy: struct ComplexEntity;
begin
MyComplexEntity.SourceRecord := SomeRecordid;
MyComplexEntity.ProcessType := enum::"My Process Type Enum"::Process1;
MyComplexEntity.RelatedRecords.Add(SomeRelatedRecordId1);
MyComplexEntity.RelatedRecords.Add(SomeRelatedRecordId2);
MyComplexEntity.RelatedRecords.Add(SomeRelatedRecordId3);
Result.Add(MyComplexEntity);
end;
procedure ProcessRecords()
var
MyEntityList: Lst of [Struct ComplexEntity];
CurrComplexEntity: struct ComplexEntity;
RelatedRecordId: RecordId;
MyprocessingInterface: Interface "IProcess Interface";
begin
MyEntityList.AddRange(GetRecords);
MyEntityList.AddRange(GetRecords2);
Foreach CurrComplexEntity in MyEntityList do begin
foreach RelatedRecordId in CurrComplexEntity.RelatedRecords do begin
MyProcessingInterface := CurrComplexEntity.ProcessType;
MyProcessingInterface.Process();
end;
end;
end;
}
It would move us away from some of those var Record design patterns we end up having to use and allow more readable/modern code.
Extra points if we can add easy conversion to/from Json/XML ;)
Comments
Additionally we had the following requirment some time agoa list of InterfacesCurrently we often use codeunits as complex (dynamic type).And it would be really helpful if I could specify the following:ComplexList: List of [Interface "PTE Interface"]See also there: https://github.com/microsoft/BCApps/issues/298#issuecomment-1824030146
Category: Development
Today I thought of something similiar:a list of CodeunitsCurrently we often use codeunits as complex (dynamic type).And it would be really helpful if I could specify the following:ComplexList: List of [Codeunit "PTE Complex Parameters"]
Category: Development
Business Central Team (administrator)
Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team