Skip to content

Commit

Permalink
Add IsPrimaryKey to AttributeJson
Browse files Browse the repository at this point in the history
  • Loading branch information
acjdekorte committed May 31, 2024
1 parent 7154c6f commit 8c20860
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions businessCentral/app/src/CDMUtil.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,20 @@ codeunit 82566 "ADLSE CDM Util" // Refer Common Data Model https://docs.microsof
DataFormat,
FieldRef.Name,
AppliedTraits,
FieldRef.Length));
FieldRef.Length,
IsPrimaryKeyField(RecordRef.Number, FieldRef.Number)
));
end;
ADLSESetup.GetSingleton();
if ADLSESetup."Delivered DateTime" then begin
GetCDMAttributeDetails(FieldType::DateTime, DataFormat, AppliedTraits);
Result.Add(
CreateAttributeJson(GetDeliveredDateTimeFieldName(), DataFormat, GetDeliveredDateTimeFieldName(), AppliedTraits, FieldRef.Length));
CreateAttributeJson(GetDeliveredDateTimeFieldName(), DataFormat, GetDeliveredDateTimeFieldName(), AppliedTraits, FieldRef.Length, false));
end;
if ADLSEUtil.IsTablePerCompany(TableID) then begin
GetCDMAttributeDetails(FieldType::Text, DataFormat, AppliedTraits);
Result.Add(
CreateAttributeJson(GetCompanyFieldName(), DataFormat, GetCompanyFieldName(), AppliedTraits, FieldRef.Length));
CreateAttributeJson(GetCompanyFieldName(), DataFormat, GetCompanyFieldName(), AppliedTraits, FieldRef.Length, false));
end;
end;

Expand All @@ -156,13 +158,23 @@ codeunit 82566 "ADLSE CDM Util" // Refer Common Data Model https://docs.microsof
exit(DeliveredDateTimeFieldNameLbl);
end;

local procedure CreateAttributeJson(Name: Text; DataFormat: Text; DisplayName: Text; AppliedTraits: JsonArray; MaximumLength: Integer) Attribute: JsonObject
procedure IsPrimaryKeyField(TableId: Integer; FieldId: Integer): Boolean
var
FieldTable: Record Field;
begin
if FieldTable.Get(TableId, FieldId) then
exit(fieldTable.IsPartOfPrimaryKey);
end;

local procedure CreateAttributeJson(Name: Text; DataFormat: Text; DisplayName: Text; AppliedTraits: JsonArray; MaximumLength: Integer; IsPrimaryKeyField: Boolean) Attribute: JsonObject
begin
Attribute.Add('name', Name);
Attribute.Add('dataFormat', DataFormat);
Attribute.Add('appliedTraits', AppliedTraits);
Attribute.Add('displayName', DisplayName);
Attribute.Add('maximumLength', MaximumLength);
if IsPrimaryKeyField then
Attribute.Add('isPrimaryKey', true)
end;

procedure CheckChangeInEntities(EntityContentOld: JsonObject; EntityContentNew: JsonObject; EntityName: Text)
Expand Down

0 comments on commit 8c20860

Please sign in to comment.