microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
780 stars 617 forks source link

[Extensibility-enhancement] Additional key in Field Table #4499

Closed PauliusRudminas closed 4 years ago

PauliusRudminas commented 5 years ago

Hello, I've created a function, that gets a value from a field, when only the names of the table and the field are known. I use the Field table to get the table and field numbers, but it seems the CodeCop code analyzer gives me a warning: "The table Field does not contain the key with the field TableName.AL(AA0210)". Likewise, a warning on Setrange for field name.

Could you please add a key in this table for table and field names? Or will this warning be irrelevant when publishing the extension to AppStore?

AlexanderYakunin commented 5 years ago

@JesperSchulz - can you help with this question?

PauliusRudminas commented 4 years ago

Hello,

Maybe there is some info on this issue?

AlexanderYakunin commented 4 years ago

This is system table and we cannot add keys here.

PauliusRudminas commented 4 years ago

Well alright, but then the question remains - if this will be an issue when publishing because of CodeCop, and we should we figure out a workaround, or - if this can be viewed as an exception and will not cause problems publishing?

JesperSchulz commented 4 years ago

I don't think a warning will prevent you from publishing to AppSource. But we should probably address the warning anyway. Looping in @MarcHansenMicrosoft.

MarcHansenMicrosoft commented 4 years ago

Only AppSourceCop is required.

Could you send a sample code? I am interested in the exact repro and if would should add the key to the system table.

Thanks Marc

PauliusRudminas commented 4 years ago

Thanks for the quick reply! Here are the two functions used:

[TryFunction]
procedure GetFieldValueFromID(ReqTableNo: Integer; ReqTableView: Text; ReqFieldNo: Integer; var ResultValue: Variant)
var
    RecRef: RecordRef;
    FldRef: FieldRef;
begin
    RecRef.OPEN(ReqTableNo);
    IF ReqTableView <> '' THEN
        RecRef.SETVIEW(ReqTableView);
    RecRef.FINDFIRST();
    FldRef := RecRef.FIELD(ReqFieldNo);
    ResultValue := FldRef.VALUE();
end;

[TryFunction]
procedure GetFieldValueFromName(ReqTableName: Text; ReqTableView: Text; ReqFieldName: Text; var ResultValue: Variant)
var
    FldRec: Record Field;
begin
    FldRec.SETRANGE(TableName, ReqTableName);
    FldRec.SETRANGE(FieldName, ReqFieldName);
    FldRec.FINDFIRST();
    GetFieldValueFromID(FldRec.TableNo, ReqTableView, FldRec."No.", ResultValue);
end;
MarcHansenMicrosoft commented 4 years ago

Thanks for the sample.

AA0210 is not a warning but just a information, meaning you should be aware. image

If you have performance issues in this code you should either avoid setting this filter or send us a request to add this key to the system table.

Thanks Marc

PauliusRudminas commented 4 years ago

Ok, thank you for the reply