
table 50000 "NVX Country Statistics"
{
DataClassification = SystemMetadata;
Caption = 'NVX Country Statistics';
TableType = Temporary;
fields
{
field(1; "Country/Region Filter"; Code[10])
{
DataClassification = SystemMetadata;
Caption = 'Country/Region Filter';
TableRelation = "Country/Region".Code;
}
field(10; "Sales (LCY)"; Decimal)
{
DataClassification = SystemMetadata;
Caption = 'Sales (LCY)';
}
field(11; "No. of Pstd. Invoices"; Integer)
{
DataClassification = SystemMetadata;
Caption = 'No. of Pstd. Invoices';
}
}
keys
{
key(Key1; "Country/Region Filter")
{
}
}
}
Die Codeunit für die Berechnung ist folgendermaßen aufgebaut:
codeunit 50000 "NVX Country Statistics"
{
TableNo = "NVX Country Statistics";
trigger OnRun()
var
NVXCountryStatistics: Record "NVX Country Statistics";
Customer: Record Customer;
begin
if not Rec.IsTemporary() then
exit;
//Die Summe wird in diesem Beispiel über die Debitoren ermittelt.
//Eventuell gesetzte Länder-/Regionsfilter müssen also von der temporären Tabelle auf die Debitoren übertragen werden.
//Der Filter auf der temporären Tabelle wird in diesem Beispiel danach entfernt, da das Feld nur für die Filterung der Debitoren verwendet wird.
Customer.SetCurrentKey("Country/Region Code");
Rec.FilterGroup(0);
Customer.FilterGroup(0);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
Rec.FilterGroup(2);
Customer.FilterGroup(2);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
//set relation filter
//Der Excel Report Builder übergibt Filter aus Verknüpfungen über Filtergruppe 11
Rec.FilterGroup(11);
Customer.FilterGroup(11);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
Rec.FilterGroup(0);
Customer.FilterGroup(0);
NVXCountryStatistics.Copy(Rec);
Clear(Rec);
Rec."Country/Region Filter" := '';
Rec.Insert();
if Customer.FindSet() then
repeat
Customer.CalcFields("Sales (LCY)", "No. of Pstd. Invoices");
Rec."Sales (LCY)" += Customer."Sales (LCY)";
Rec."No. of Pstd. Invoices" += Customer."No. of Pstd. Invoices";
Rec.Modify();
until Customer.Next() = 0;
Rec.Copy(NVXCountryStatistics);
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"NCE Temp. Data Codeunit Mgt.", 'OnAddAllowedTempDataCodeunits', '', false, false)]
local procedure NCETempDataCodeunitMgt_OnAddAllowedTempDataCodeunits(var TempNCETempDataCodeunit: Record "NCE Temp. Data Codeunit" temporary)
var
NVXCountryStatistics: Record "NVX Country Statistics";
CountryRegion: Record "Country/Region";
RecField: Record Field;
CodeunitID: Integer;
TableID: Integer;
TableSettingsName: Text;
HelpTxt: Label 'This Codeunit calculates the total for all countries within the filter.';
FiltersAndRelationsHelpTxt: Label '\\Filters and Relations:\The filter in the ''%1'' field determines which Countries/Regions should be included in the evaluation.';
ResultsHelpTxt: Label '\\Results:\''%1'', ''%2''';
begin
CodeunitID := Codeunit::"NVX Country Statistics";
TableID := Database::"NVX Country Statistics";
TableSettingsName := NVXCountryStatistics.TableCaption();
TempNCETempDataCodeunit.Add(CodeunitID, TableID, TableSettingsName,
HelpTxt +
StrSubstNo(FiltersAndRelationsHelpTxt, NVXCountryStatistics.FieldCaption("Country/Region Filter")) +
StrSubstNo(ResultsHelpTxt, NVXCountryStatistics.FieldCaption("Sales (LCY)"), NVXCountryStatistics.FieldCaption("No. of Pstd. Invoices")));
TempNCETempDataCodeunit.AddTableFilter(CodeunitID, NVXCountryStatistics.FieldNo("Country/Region Filter"));
TempNCETempDataCodeunit.AddTableFilter(CodeunitID, Database::"Country/Region", NVXCountryStatistics.FieldNo("Country/Region Filter"), '', CountryRegion.FieldNo(Code));
Clear(RecField);
RecField.SetRange(TableNo, TableID);
RecField.SetFilter("No.", '<%1', 2000000000);
RecField.SetRange(Enabled, true);
if RecField.FindSet() then
repeat
if (RecField."No." <> NVXCountryStatistics.FieldNo("Country/Region Filter")) then
TempNCETempDataCodeunit.AddDataSheetField(CodeunitID, RecField."No.");
until RecField.Next() = 0;
end;
}
codeunit 50001 "NVX Country Statistics 2"
{
TableNo = "NVX Country Statistics";
trigger OnRun()
var
NVXCountryStatistics: Record "NVX Country Statistics";
Customer: Record Customer;
begin
if not Rec.IsTemporary() then
exit;
//Die Summe wird in diesem Beispiel über die Debitoren ermittelt.
//Eventuell gesetzte Länder-/Regionsfilter müssen also von der temporären Tabelle auf die Debitoren übertragen werden.
//Der Filter auf der temporären Tabelle wird in diesem Beispiel danach entfernt, da das Feld nur für die Filterung der Debitoren verwendet wird.
Customer.SetCurrentKey("Country/Region Code");
Rec.FilterGroup(0);
Customer.FilterGroup(0);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
Rec.FilterGroup(2);
Customer.FilterGroup(2);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
//set relation filter
//Der Excel Report Builder übergibt Filter aus Verknüpfungen über Filtergruppe 11
Rec.FilterGroup(11);
Customer.FilterGroup(11);
Rec.CopyFilter("Country/Region Filter", Customer."Country/Region Code");
Rec.SetRange("Country/Region Filter");
Rec.FilterGroup(0);
Customer.FilterGroup(0);
NVXCountryStatistics.Copy(Rec);
Clear(Rec);
if Customer.FindSet() then
repeat
if not Rec.Get(Customer."Country/Region Code") then begin
Clear(Rec);
Rec."Country/Region Filter" := Customer."Country/Region Code";
Rec.Insert();
end;
Customer.CalcFields("Sales (LCY)", "No. of Pstd. Invoices");
Rec."Sales (LCY)" += Customer."Sales (LCY)";
Rec."No. of Pstd. Invoices" += Customer."No. of Pstd. Invoices";
Rec.Modify();
until Customer.Next() = 0;
Rec.Copy(NVXCountryStatistics);
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"NCE Temp. Data Codeunit Mgt.", 'OnAddAllowedTempDataCodeunits', '', false, false)]
local procedure NCETempDataCodeunitMgt_OnAddAllowedTempDataCodeunits(var TempNCETempDataCodeunit: Record "NCE Temp. Data Codeunit" temporary)
var
NVXCountryStatistics: Record "NVX Country Statistics";
CountryRegion: Record "Country/Region";
RecField: Record Field;
CodeunitID: Integer;
TableID: Integer;
TableSettingsName: Text;
HelpTxt: Label 'This Codeunit calculates the total for each country within the filter.';
FiltersAndRelationsHelpTxt: Label '\\Filters and Relations:\The filter in the ''%1'' field determines which Countries/Regions should be included in the evaluation.';
ResultsHelpTxt: Label '\\Results:\''%1'', ''%2'', ''%3''';
begin
CodeunitID := Codeunit::"NVX Country Statistics 2";
TableID := Database::"NVX Country Statistics";
TableSettingsName := NVXCountryStatistics.TableCaption();
TempNCETempDataCodeunit.Add(CodeunitID, TableID, TableSettingsName,
HelpTxt +
StrSubstNo(FiltersAndRelationsHelpTxt, NVXCountryStatistics.FieldCaption("Country/Region Filter")) +
StrSubstNo(ResultsHelpTxt, NVXCountryStatistics.FieldCaption("Country/Region Filter"), NVXCountryStatistics.FieldCaption("Sales (LCY)"), NVXCountryStatistics.FieldCaption("No. of Pstd. Invoices")));
TempNCETempDataCodeunit.AddTableFilter(CodeunitID, NVXCountryStatistics.FieldNo("Country/Region Filter"));
TempNCETempDataCodeunit.AddTableFilter(CodeunitID, Database::"Country/Region", NVXCountryStatistics.FieldNo("Country/Region Filter"), '', CountryRegion.FieldNo(Code));
Clear(RecField);
RecField.SetRange(TableNo, TableID);
RecField.SetFilter("No.", '<%1', 2000000000);
RecField.SetRange(Enabled, true);
if RecField.FindSet() then
repeat
TempNCETempDataCodeunit.AddDataSheetField(CodeunitID, RecField."No.");
until RecField.Next() = 0;
end;
}
Wird die Codeunit nach deren Veröffentlichung in einem Datenblatt hinzugefügt, werden wie in Beispiel 1 automatisch Felder und Verknüpfungen vorgeschlagen:
![]() | Finmatics Autonomous Accounting Schnittstelle für KI-gesteuerte Belegverarbeitung von Finmatics. Weitere Informationen ![]() |