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:

z7ln4t4vmhgn.png


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:

https://drive.google.com/open?id=1idp7D3mN5J8BImwoc_i3GLqZ98CKU3hI

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:

cd4es4kxmy34.png


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:

b4xp4gcnsnl4.png

The add-in itself: https://drive.google.com/open?id=1AaFqbVp-E0HrvcdqSpY3t_HdyAKj4KyG
Sign In or Register to comment.