JavaScript for Multiple Attachments on WEB

rinagreenrinagreen Posts: 16Member
edited 2019-03-18 in NAV Three Tier
We all love NAV for its functionality and wide spectrum of built-in financial and management features.
However, we have to admit that in terms of User Interface the system can be not very friendly sometimes. Besides, there are many restrictions (such as inability to use .Net objects on Web Client) which often force developers either to abandon realization of clients’ requirements or to design sophisticated ineffective solutions that take a lot of time.
Being in the beginning of my career as a Navision Developer, I dreamed big and craved to find a way to make impossible possible. Thanks to Vjeko, I discovered JavaScript and this article is about my second experience of implementation JS in Navision.
The matter was very simple – to allow our users to attach many files to financial and logistics documents at a time. Standard functionality solves the problem perfectly! For RTC... But on Web Client we had this annoying error message:


After four days of playing in JavaScript sandbox, I ended up with a little Add-In which allowed to choose/drop multiple files to attach, edit some information about the files and actually upload them into the system binding with a certain Navision document. The video below shows how it works:

The most difficult part of the process (for me) was to transfer files from JavaScript Add-In to the server side and to save them in a particular folder. Surprisingly, the code for this purpose took just a couple of lines and, more surprisingly, it implied .Net which worked on Web Client:


The first function - FromBase64String gets string representation of a file in Base64 format and turns it to BLOB, the second function – BLOBExportToServerFile gets BLOB-representation of the file and turns it into an actual file on server wherever we want to store it.
How do we get this string representation in Base64 format? FileReader on JavaScript side will help:


The add-in itself:
Sign In or Register to comment.