This post is machine-translated. The original post in german language can be found here.

Suppress Best-Practice Deviations

In principle, every solution in Dynamics 365 for Finance and Operations should be free of best-practice deviations, but sometimes there is the need to suppress them.

Such a case are for example, event handlers that have a predefined parameter profile, but if one of these parameters is not used, it causes a BP deviation.

class MyFreeTextInvoiceHeaderFooterTmpEH
{
    [DataEventHandler(tableStr(FreeTextInvoiceHeaderFooterTmp), DataEventType::Inserting)]
    public static void FreeTextInvoiceHeaderFooterTmp_onInserting(Common sender, DataEventArgs e)
    {
        FreeTextInvoiceHeaderFooterTmp freeTextInvoiceHeaderFooterTmp;
    
        freeTextInvoiceHeaderFooterTmp = sender;
    
        if (freeTextInvoiceHeaderFooterTmp.CompanyBankAccount == "")
        {
            freeTextInvoiceHeaderFooterTmp.CompanyBankName = "Unknown";
        }
    }
}

With the above EH, the following BP deviation would be output because the parameter e is not used:

BP Rule: [BPParameterNotUsed]:The parameter 'e' is not used.

To prevent this, you can use the attribute SuppressBPWarning in the simplest case:

class MyFreeTextInvoiceHeaderFooterTmpEH
{
    [DataEventHandler(tableStr(FreeTextInvoiceHeaderFooterTmp), DataEventType::Inserting),
    SuppressBPWarning('BPParameterNotUsed', 'False positive')]
    public static void FreeTextInvoiceHeaderFooterTmp_onInserting(Common sender, DataEventArgs e)
    {
        FreeTextInvoiceHeaderFooterTmp freeTextInvoiceHeaderFooterTmp;
    
        freeTextInvoiceHeaderFooterTmp = sender;
    
        if (freeTextInvoiceHeaderFooterTmp.CompanyBankAccount == "")
        {
            freeTextInvoiceHeaderFooterTmp.CompanyBankName = "Unknown";
        }
    }
}

But it is also possible to collect all these suppressions in a module-bound file. To do this, you must create an XML file in the directory of the module as follows:

K:\AosService\PackagesLocalDirectory\YourModel\YourModel\
AxIgnoreDiagnosticList\YourModel_BPSuppressions.xml

<?xml version="1.0" encoding="utf-8"?>
<IgnoreDiagnostics>
  <Name>YourModel_BPSuppressions</Name>
  <Items>
    <Diagnostic>
      <DiagnosticType>BestPractices</DiagnosticType>
      <Severity>Warning</Severity>
      <Path>dynamics://Class/MyFreeTextInvoiceHeaderFooterTmpEH/Method/FreeTextInvoiceHeaderFooterTmp_onInserting</Path>
      <Moniker>BPParameterNotUsed</Moniker>
      <Justification>Event handler parameters that cannot be removed from the method&apos;s signature.</Justification>
    </Diagnostic>
  </Items>
</IgnoreDiagnostics>

Please note that in XML the name of the model must be adapted to the circumstances.

DiagnosticType is always "BestPractices". Severity, Path and Moniker can usually be read from the error message in the error list of Visual Studio. Unfortunately, in my experience, this is not always the case. In this case you can read on this page if you find a suitable moniker:

https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-tools/customization-analysis-report

I myself have come across the following Monikers so far:

  • BPParameterNotUsed
  • BPEmptyCompoundStatement
  • BPErrorMethodUnbalancedTtsbeginCommit
  • BPCheckParametersModified
  • BPUpgradeCodeLateBoundCall
  • BPErrorClassNewNotProtected

Once you have created such an XML file, you can use the context menu of the Visual Studio project to edit the file: Edit Best Practice Suppressions

By the way, you can store an XML schema for this XML file in the same directory to avoid the following error:

Could not find schema information for the element 'IgnoreDiagnostics'.

Such a schema can be created in Visual Studio under XML > Create schema (this menu is only available if you have just opened an XML file). 

To add the XML file (and the schema, if applicable) to the version control, you have to change to the directory of the corresponding model via the Source Control Explorer and select the files via Add Items to Folder.

By the way, I made the experience that you should edit the XML file outside of Visual-Studio.

These post applies to following version:
Dynamics 365 for Finance and Operations

Add comment
 
 

 

 
 
 
Posts of the actual month
August 2022
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
293031 
 
© 2006-2022 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.