D365FO ER (GER): Error while evaluating expression…

If you work with Electronic Reporting, you probably have faced an error like this more than once:

In this post (and you have the video version of it in YouTube), we are going to understand why this pretty common error happens, giving us the tools to see what is wrong, and troubleshooting the error. We are going to see 2 different examples, first didactic one, made out by me to force the error and help us understand it, and second one, a real ER error from the OOB BAI2 Bank statements, that I had to face lately in a project.

First example, didactic

The first example consists of just an export of a sales order and lines to an XML file:

Having this model:

this format:

And, important, this model mapping:

So, if we analyze the model mapping (that is where this error is normally introduced), it is getting an input parameter, and filtering the sales table. That works fine when you select a valid Sales Id, like for example:

Will generate:

Perfect, but what if I don’t select a Sales Id? Then:

Well, if you take a closer look at the model mapping:

We are just assigning the value CustAccount and SalesId from a filtered list. That filtered list is actually a record list (that we know it is max one record, since we are filtering by the Sales Id that is unique), though it will still fail when there’s no record, since the CustAccount and SalesId Cannot be evaluated, because the SalesTableFiltered is a null object (no records). So that’s what that error means, it can also occur when there are errors casting different incompatible data types, that will lead to the node not being evaluated.

In order to fix it in this case, we can use the function FirstOrNull(). That will convert our record list in a record, getting the first element, and in case of an empty record list, it will give us a record with the empty values of it’s data types, that means having SalesId = “”, instead of Null, and preventing that way the error to happen.

Now, when I just put a bad filter, with no sales orders, the file will have no data, but it won’t throw the error, and it will be generated.

Second example, error while importing BAI2 file for bank statements.

The other day, I received an email from a functional teammate saying that she is receiving this weird error when trying to import a bank statement:

Poor her… there was no way she could have known why the error was actually happening, since the error description just mess things up more than helping. This is a very common error that I’ve seen dozens of times, so I decided to make this post, and also I decided to include that example, since I always like to make this blog as close as real life as possible (without losing the didactic purpose). In this case, if we go to the OOB format, we are going to see nothing there, since that parsing is that in the model mapping:

But that FileString, that is containing absolutely the whole file text, is parsed in the model mapping, so there we should look for our $StatementValidated.DataAreaId node that our error is complaining about:

As we see there, and per our experience in the previous simple example, there’s no way the DataAreaId itself is the cause of the problem, I’d assume the problem here is that the StatementValidated is returning no records (Where the function returns a filtered record list as well). In the where condition we see that IsBankAccountValid is the filtering criteria, and thus, it is probably not matched in our file import execution. I, of course, went deeper into it and checked what that IsBankAccountValid calculated field was based on, and the Electronic Reporting model mapping gets more and more complicated, however, with the information about the BankAccount not being valid, I reached back to my functional teammate, and we looked for the bank accounts in the file, confirming that the bank account was in fact not configured properly in the environment. After making the adjustment in the configuration, the import worked successfully.

Thanks for reading till the end! If you liked this post remember there’s a lot of Electronic Reporting related posts in the blog, as well as videos in my YouTube channel, see you there!


Leave a comment