Changing report language at runtime

D365FO selects the reporting language based on several factors. In most cases, the language is either the one set on the customer for outgoing documents or the one set on the user for incoming documents. Users can change the language by overriding these default values before posting the documents and then the newly selected language will be used.

Despite this flexibility, you may wish to explicitly set the language using your own logic. In this article, you will learn how to do just that.

Docentric AX offers a powerful API with which you can define the report language at runtime, among other things. You can specify a language in the DSP class by modifying the preRunGenerateDS() method where you can substitute the language. The following example uses the hardcoded setting for the Italian language on the HcmNumberOfWorkers report.

class DocHcmNumberOfWorkersDSP extends DocDataSourceProviderSrsReporting
    public ClassDescription description()
        return 'Docentric Examples: HcmNumberOfWorkders DSP';
    protected void preRunGenerateDS()
        // Initialize here the class global variables.
        HcmNumberOfWorkersContract reportContract;
        reportContract = this.getSrsRdpContract();
        LanguageId lang = 'it'; 

In the preRunGenerateDS() method you instantiate the report contract class for your report. Then you could read the language from somewhere else (customer, user or some other source) where I hard-coded Italian language. Upon execution, the report correctly reads labels in selected language.

Additionally, it is also possible to set the language in the method override-reportrunsettings() by adding the code below:


This code, as you see, is using the language, set for the customer.