In this post, we will try to understand the need to download a PDF file from the backend in a single click in VBCS. Let us go through the Problem first and then we will cover the Solution and Conneqtion Approach.
The Problem
Saving a PDF file as base64 in the backend will be a random combination of numbers and letters. Now, what if the user wants to download the same PDF file from the backend on a click of a button in VBCS.
The Solution
Assuming there is already some kind of a ‘Download’ button that fires an API request when clicked on, which returns the response in bas64 format. Then, using the small JavaScript code we can achieve this functionality.
Conneqtion Approach
Step 1: Open VBCS Application in Development Mode.
Step 2: Configure the REST API which returns the base64 as response in the connection.
Step 3: Add below piece of JavaScript code in the PageModule function.
The code above is pretty self-explanatory but we will try to simplify it for you with a tiny explanation.
The JavaScript code creates an anchor tag element assigned to the constant download-Link , uses the base64 pdf along with “octet/stream” as a href attribute, adds a download attribute with the name of the file. Then clicks on the created link to download the pdf. It’s that simple.
Step 4: Create a new button event – ojAction and configure the action items as shown in the screenshot below
Step 5: Assign Input parameter to the repairBase64 function.
Step 6: Assign input parameter to the downloadByteFile function
1) Data will be output of repairBase64 functional.
2) name will be file name.
Shahzad
I am using the same approach for calling the BIP report from vbcs application but every time error is comming like the string need to be decoded is not in correct encode format. Can you please guide me or share some sample document or application which you have developed.
Karan Tulsani
Hi Shahzad,
What is the report format which you’re calling from OIC? Is it in pdf or any other format?
If the report format is not pdf then this method is not suitable.
Thanks.