ForNAV Tips Part 4: How to Implement Business Central Reports in AL Projects

May 7, 2021 Justin Arnold

This is the fourth of a six-part series discussing how businesses using Microsoft Dynamics 365 Business Central can analyze their financial health by leveraging ForNav tools to streamline reporting processes for generating key performance indicators. This article presents how to take the converted report created from the previous article—Part 3: How to Convert Classic NAV Reports in Business Central—and plug it into an AL programming language project. From there, you can tailor the report to work correctly in Business Central and then package and upload it to the cloud for testing. 

 

Moving Converted Reports to an AL Programming Language Project

When we left off in Part 3 of this series, we had converted a sales order report. The conversion resulted in two folders and one file:

  1. Layout folder
  2. Translations folder
  3. Converted report object file (in .txt format)

 

For this example, ignore the [Translations] folder. That will be handled separately by the existing project.  For now, focus on the [Layout] folder and report files. Installing them into your project is pretty much just a copy-and-paste operation. All you need to do is copy the converted report [SalesOrder.Report.txt] and place it in the [src/report] directory of your AL project. 

After copying the report over, change the extension from [.txt] to [.al], otherwise it will not be recognized as a valid AL file in your project. So instead of [SalesOrder.Report.txt], you would now have [SalesOrder.Report.al].

Next, move the layout into the src/layout folder of your AL project. Upon completion, your report and layout directories should look something like this: 

 

Keep in mind that in this example, we are working with an existing project, so there are report and layout files already present. This may or may not be the case for your project, especially if you created it from scratch. Either way is fine—all that matters is getting the report and layout into the correct directories. From there, you can move over to VS Code and begin making your edits.

 

Updating Converted Report in VS Code: The General Set-Up

If you open your project in VS Code, you will see the addition of your converted report and layout files:

 

For this example, don’t worry about the layout. There is nothing that will need to be done there. For the [Sales Order] report file, you can see right away in the screenshot below that 16 errors must be handled before this report can be packaged. There are also a few standard adjustments to make as well. The next section describes those changes.

First, update the general report information:

 

There are a couple of issues here that you can resolve quickly. First, change your report ID. I have an [app.json] file that allows a range of [50000] thru [50200], so I will use [ID 50050]. And in this case, I also changed the name of my report to match the naming convention for Western Computer. Not everybody will necessarily do this, but I encourage you to use naming conventions specific to the objects so you do not conflict with another project or add-on later on. 

For this example, I call the report [WC Sales Order]. You should also update the object filename as well. The naming convention I use dictates my report object to be renamed as [Rep50050.WCSalesOrder.al].  

Next, update the [WordLayout] path. Presently, it reflects what ForNAV anticipates your path to be—based on the base paths ForNAV sets up when you create a project from scratch using the designer. Since I did not create my project this way, I need to update the file path to match my project. 

Thus, the path changes from…

WordLayout = './Layouts/Sales Order.docx';

to…

WordLayout = './src/report/Layout/Sales Order.docx';

 

Finally, add the [UsageCategory] and [ApplicationArea] properties to the report. This allows you to run the report from the search bar in Business Central. You will not want to do this with all reports, particularly those intended to run only from a menu button or report selections. But in this case, it’s best to allow users to search for the report. When completed, the report properties will look something like this:

 

 

Note: Objects are now required to have XML Documentation Comments. To auto-generate a comment, just type three-forward slashes [///] and select the option to create the comment. If you do not, you will receive a warning.  Note: I find this warning truly annoying.  It can be disabled in your project settings by changing the following options to “Disabled:” - Al-xml-doc: Check Object Documentation Information Level and Al-xml-doc: Check Procedure Documentation Information Level.  This can be disabled at the User or Workspace level.
 

Updating Converted Report in VS Code: Error Handling

Now that we finished with the formalities, it’s time to correct our errors. Let’s take each error in turn. 

ERROR: Record Tax Area does not contain a definition for Country

 

The [Tax Area] table in NAV version 5.0 had a field called [Country]. In BC V.17, the field is now called [Country/Region]. To correct this, update the field reference. Also observe that this error occurs four separate times in this report. So rather than just fixing it here, you can update all occurrences of [TaxArea.Country] by using [Find] and [Replace]:

Now you have five fewer errors to deal with!

 

ERROR: Operator cannot be applied to operands of type Text and Integer

 

This error is unfortunately a ForNAV bug. I spoke with their development team, and they are looking into it. For now, you will need to adjust this so it will not create an error condition. 

 

Let’s look at what [Text001] is:

 

These are labels for our trans-headers and trans-footers. Let’s go ahead and adjust them accordingly:

 

Now let’s address the original error:

 

What you have effectively done is change the trans header/footer from [Transferred to/from page X] to [Transferred to/from previous/next page]. In other words, you eliminated the page number calculation causing the error. Now do this for both [Text001] and [Text002].

 

ERROR: There is no argument given that corresponds to the required formal parameter SalesHeader of SalesHeaderShipTo (var array[8] of Text[100], array[8] of Text[100], var Record Sales Header)

 

This is a complicated way of saying you are missing a parameter in the function call [FormatAddress.SalesHeaderShipTo]. All you need to do is add an extra [ShipToAddress] parameter to correct the error:

 

Note: You will see this error on almost any document-style report converted from classic NAV.

 

ERROR: Table UnknownRecord8 is missing

 

In classic NAV, this record variable is referenced as the [Language] table. In BC V.17, you need to change it to point to the [Language] codeunit. The [Language] record variable is now obsolete:

 

ERROR: An implicit conversion is being performed from a value of type Enum Sales Line Type to a value of type Integer. This conversion can lead to unexpected runtime issues. This warning will become an error in a future release.

 

The [Type] is now an [Enum], meaning you cannot treat it as an option anymore, or at least not exactly. You need to append [.AsInteger] to [Type] and then it will compile:

if Type.AsInteger() = 0 then begin

 

ERROR: The With statement is deprecated and will be removed for cloud development in a future release. This warning will become an error in a future release.

Unfortunately, you can no longer utilize implicit/explicit [WITH] statements. I know, I’m sad too! 

I used these things all the time to simplify my code. Fortunately, you do have access to a very effective tool to update explicit [WITH] statements.

Here’s an example: Click on the error in the [PROBLEMS] window. This takes you to the spot in your code where the [WITH] statement is used. Right-click on the error (from the problems window) and select [Convert the ‘with’ statement to fully qualified statements]:

 

 

As you can see in the image above, the [with TempSalesTaxAmtLine do begin] statement has been rearranged so that [TempSalesTaxAmtLine] is now appended to the appropriate lines of code. This is a great time saver! 

Repeat for the five remaining errors, which are exactly the same issue:

 

 

Note: For this to work, you must enable [Code Actions] in either your user or workspace settings:

 

Now our project is error-free! You can package and deploy in your cloud database.

 

Packaging and Uploading to the Cloud

Before packaging your report, update your [app.json] file with the correct version. If this is the first time you deployed anything in the project, leave the version as is. If it is not, increment the version number by one. In this case, your new version would be [1.0.0.140]:

 

 

Next, hit [Ctrl} + [Shift] + [P], and select [AL package] to create the app file:

Now you are ready to rock and roll! From here, open your cloud database and navigate to [Extension Management]. [Uninstall]  and optionally [Unpublish] any previous versions of your extension:

Then upload your new extension, accept the licensing agreement, and hit [Deploy]:

 

You have to wait a few minutes while the extension deploys, but you can check the status of a deploying extension by selecting [Manage] then [Deployment Status]:

 

Once the status says [Completed], you can close the database and reopen it. Your report is now ready to run:

 

After reopening the database, navigate to [ForNAV] then [My Reports]:

 

You can now select and run your new report by going to [Report] then [Run]:

 

Enter an appropriate filter to limit the reporting criteria. For this example, I filtered on a sales order that already exists in the database:

 

 

Hit preview to view the report:

 

Looks good! 

One thing to note, the [Reports ForNAV Trial Version] text running down the left side of the page indicates you are using a trial version. Once you purchase a ForNAV license, this message goes away.

That about does it for using ForNAV to convert Classic NAV Reports. You have now officially converted your first classic report and without too much fuss!

I hope this information was helpful. In our next article, we will discuss how to use custom report layouts in ForNAV to make updates to converted reports. In the meantime, if you have any questions about Business Central or ForNAV, feel free to reach out to me at info@westerncomputer.com.

 

 

About the Author

Justin Arnold

With a focus on the technical and functional aspects of Dynamics 365 Business Central, Justin Arnold has worked for Western Computer since 2016.

More Content by Justin Arnold
Previous Article
How to Use Enterprise Asset Management for D365 Finance and Supply Chain Management
How to Use Enterprise Asset Management for D365 Finance and Supply Chain Management

Read our blog post on How to Use Enterprise Asset Management for D365 Finance and Supply Chain Management b...

Next Article
Speed Up Quote-to-Order Process to Give Your Sales Team More Time for Customers
Speed Up Quote-to-Order Process to Give Your Sales Team More Time for Customers

Implement a faster quote to order process to give your sales team more time to improve client relationships...

×

Would you like to speak to a Microsoft Dynamics expert? Contact us today:

First Name
Last Name
Product I'd like a demo of:
!
Thank you, we will be in touch shortly!
Error - something went wrong!