Nico
Nico

Reputation: 1197

Possibility to modify or extend code in D365FO to suppress thrown error

Original class function creates an SQL query and executes it. Since there is an syntax error in the query it throws an error. What's the correct way to achieve fixation? Class extension does not work, because CoC executes the complete original function.

originalFunction(..)
{
    createSomeSQLQueryWithSyntayErrorInIt();
    executeQuery();
}

The class in question is ReqDemPlanMissingForecastFiller. In method insertMissingDatesForecastEntries a direct SQL statement string is generated. The date variable nonFrozenForecastStartDate is added to the string, but is not escaped correctly as it seems.

If the SQL statement is executed, a syntax error occurs. If the statement is fixed, it can be executed e.g. in SQL Server Management Studio (SSMS).

Upvotes: 3

Views: 813

Answers (2)

FH-Inway
FH-Inway

Reputation: 5107

@Jan B. Kjeldsen's answer describes how the specific case can be solved without involving Microsoft.

Since overlayering is no longer possible, the solution involves copying a fair bit of standard code. This brings its own risks, because future changes by Microsoft for that code are not reflected in the copied code.

Though it cannot always be avoided, other options should be evaluated first:

  • As @Jan B. Kjeldsen mentioned, errors in the standard code should be reported to Microsoft (see Get support for Finance and Operations apps or Lifecycle Services (LCS)). This enables them to fix the error.
    • Pro: No further work needed.
    • Con: Microsoft may decline the fix or take a long time to implement it.
  • If unlike in this specific case the issue is not a downright error, but a lack of extension options, an extensibility request can be created with Microsoft. They will then add an extension option.
    • Pro: No further work needed.
    • Con: Microsoft may decline the extensibility request or take a long time to implement it.
  • For both errors as well as missing extension options, Microsoft also offers the Community Driven Engineering program (CDE). This enables you to develop changes in the standard code directly via a special Microsoft hosted repository where the standard code is not locked for changes.
    • Pro: Most flexible and fastest of all options involving Microsoft.
    • Con: You have to do the work yourself. Microsoft may decline the change. It can still take some time before the change is available in a GA version.

You can also consider a hybrid approach: For a quick solution, copy standard code and customize it as required. But also report an error, create an extensibility request or fix it yourself in the CDE program. When the change is available in standard code, you can then remove the copied code again.

Upvotes: 3

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

In this specific case, based on your comments, you may be able to sidestep.

Create a new class ReqDemPlanMissingForecastFiller_Fix extending ReqDemPlanMissingForecastFiller then copy/paste the erroneous function and correct the mistake.

Create an extension class and change the newParameters static funcion.

[ExtensionOf(classStr(ReqDemPlanMissingForecastFiller))]
class ReqDemPlanMissingForecastFiller_Extention
{
    public static ReqDemPlanMissingForecastFiller newParameters(
        ReqDemPlanCreateForecastDataContract    _dataContract,
        ReqDemPlanAllocationKeyFilterTmp        _allocationKeyFilter,
        ReqDemPlanTaskLoggerInterface           _logger = null)
    {
        ReqDemPlanMissingForecastFiller filler = next newParameters(_dataContract, _allocationKeyFilter, _logger);
        filler = new ReqDemPlanMissingForecastFiller_Fix(); //Throw away previous value    
        filler.parmDataContract(_dataContract);
        filler.parmAttributeManager(_dataContract.attributeManager());
        filler.parmAllocationKeyFilter(_allocationKeyFilter);
        filler.parmLogger(_logger);
        filler.init();    
        return filler;
    }
}

Code above was based on AX 2012 code. Stupid solution to a stupid problem.

It goes almost without saying that you should report the problem to Microsoft.

Upvotes: 3

Related Questions