Performing calculations in NAV mappings
If you need to perform basic calculations you don’t need to write an EDI Callback function for it, you can directly do it in a NAV mapping. Here’s how to do so, explained using the example of the vat amount in an invoice.
In your sales invoice line you have the line amount, the vat base amount, the amount incl. vat etc. What you don’t directly have is the vat amount itself, it can be calculated from the vat base amount and the amount incl. vat by subtracting the latter from the former. In NAV this is done on the statistics page and in the NAV mappings we can use different assignment modes on a data mapping line:
As you can see in the picture above only the four basic calculation types “Add”, “Subtract”, “Multiply” and “Divide” are available, but that should be enough for most scenarios. For the example of the vat amount you need two mapping lines: in the first line, you add the amount incl. vat to your vat amount field. In the second line, you use the assignment mode “Substract” for the vat base amount and as the result you have the vat amount.
At this point you might think of using this method to sum up all the amount fields . Yes, that is possible but there’s an easier way to get the sums, this topic is covered in the article https://docs.anveogroup.com/en/kb/adding-sums-to-your-edi-document/.