Using FindByName, FindByCode and FindByNumber (UsingFindElementByString)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Code smell |
BSL |
Major |
Yes |
2 |
standard badpractice performance |
Description¶
The rule finds the use of the FindByName
, FindByCode
or FindByNumber
methods using specific numbers, codes and names of elements or documents.
Similar code may not work correctly in other databases.
Often such code is test code included in the release version, which is also not recommended.
It is recommended to specify constant data values from the database in "Сonstants" or predefined metadata elements.
Examples¶
Incorrect:
Position = Catalogs.Positions.FindByName("Senior Accountant");
Position = Catalogs.Positions.FindByCode("00-0000001");
or
Object = Documents.Invoice.FindByNumber("0000-000001", CurrentDate());
Acceptable use:
Catalogs.Currencies.FindByCode(CurrentData.CurrencyCodeDigital);
Catalogs.BankClassifier.FindByCode(BankDetails.BIK);
Documents.Invoice.FindByNumber(Number);
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:UsingFindElementByString-off
// BSLLS:UsingFindElementByString-on
Parameter for config¶
"UsingFindElementByString": false