Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Export Enum as Integer option to ADLSE Setup #71

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion businessCentral/app/src/CDMUtil.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ codeunit 82566 "ADLSE CDM Util" // Refer Common Data Model https://docs.microsof
end;

local procedure GetCDMDataFormat(FieldType: FieldType): Text
var
ADLSESetup: Record "ADLSE Setup";
begin
// Refer https://docs.microsoft.com/en-us/common-data-model/sdk/list-of-datatypes
// Refer https://docs.microsoft.com/en-us/common-data-model/1.0om/api-reference/cdm/dataformat
Expand All @@ -273,7 +275,13 @@ codeunit 82566 "ADLSE CDM Util" // Refer Common Data Model https://docs.microsof
FieldType::Integer:
exit('Int32');
FieldType::Option:
exit(GetCDMDataFormat_String());
begin
ADLSESetup.GetSingleton();
if ADLSESetup."Export Enum as Integer" then
exit('Int32')
else
exit(GetCDMDataFormat_String());
end;
FieldType::Time:
exit('Time');
FieldType::Boolean:
Expand Down
4 changes: 4 additions & 0 deletions businessCentral/app/src/Setup.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ page 82560 "ADLSE Setup"
end;
end;
}
field("Export Enum as Integer"; Rec."Export Enum as Integer")
{
ToolTip = 'Specifies if the enums will be exported as integers instead of strings. This is useful if you want to use the enums in Power BI.';
}
}
}
part(Tables; "ADLSE Setup Tables")
Expand Down
12 changes: 10 additions & 2 deletions businessCentral/app/src/Setup.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ table 82560 "ADLSE Setup"
{
Caption = 'Translations';
}
field(45; "Export Enum as Integer"; Boolean)
{
Caption = 'Export Enum as Integer';
trigger OnValidate()
begin
if Rec."Schema Exported On" <> 0DT then
Error(ErrorInfo.Create(NoSchemaExportedErr, true));
end;
}
}

keys
Expand All @@ -135,6 +144,7 @@ table 82560 "ADLSE Setup"
AccountNameIncorrectFormatErr: Label 'The account name is in an incorrect format.';
RecordDoesNotExistErr: Label 'No record on this table exists.';
PrimaryKeyValueLbl: Label '0', Locked = true;
NoSchemaExportedErr: Label 'Schema already exported. Please perform the action "clear schema export date" before changing the schema.';

local procedure TextCharactersOtherThan(String: Text; CharString: Text): Boolean
var
Expand Down Expand Up @@ -179,8 +189,6 @@ table 82560 "ADLSE Setup"
end;

procedure SchemaExported()
var
NoSchemaExportedErr: Label 'Schema already exported. Please perform the action "clear schema export date" before changing the schema.';
begin
Rec.GetSingleton();
if Rec."Schema Exported On" <> 0DT then
Expand Down
1 change: 1 addition & 0 deletions businessCentral/app/src/SetupAPIv11.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ page 82568 "ADLSE Setup API v11"
{
Editable = false;
}
field(exportEnumasInteger; Rec."Export Enum as Integer") { }
field(systemId; Rec.SystemId)
{
Editable = false;
Expand Down
17 changes: 16 additions & 1 deletion businessCentral/app/src/Util.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ codeunit 82564 "ADLSE Util"

procedure ConvertFieldToText(FieldRef: FieldRef): Text
var
ADLSESetup: Record "ADLSE Setup";
DateTimeValue: DateTime;
begin
case FieldRef.Type of
Expand All @@ -223,7 +224,13 @@ codeunit 82564 "ADLSE Util"
exit(ConvertDateTimeToText(DateTimeValue));
end;
FieldRef.Type::Option:
exit(FieldRef.GetEnumValueNameFromOrdinalValue(FieldRef.Value()));
begin
ADLSESetup.GetSingleton();
if ADLSESetup."Export Enum as Integer" then
exit(ConvertOptionFieldToValueText(FieldRef))
else
exit(FieldRef.GetEnumValueNameFromOrdinalValue(FieldRef.Value()));
end;
FieldRef.Type::Boolean:
exit(Format(FieldRef.Value(), 0, 9));
FieldRef.Type::Code,
Expand All @@ -235,6 +242,14 @@ codeunit 82564 "ADLSE Util"
end;
end;

procedure ConvertOptionFieldToValueText(FieldRef: FieldRef): Text
begin
case FieldRef.Type of
FieldRef.Type::Option:
exit(ConvertNumberToText(FieldRef.Value()));
end;
end;

local procedure ConvertStringToText(Val: Text): Text
var
Char10, Char13 : Char;
Expand Down
Loading