How To Read CSV File From VBCS Without OIC?

How To Read CSV File From VBCS Without OIC?

In this blog, we will show you how to read CSV file from VBCS without OIC. So, let’s begin.

First, open Visual Builder and click on New on the right side of the window.

Article content
Article content

Give the name of the Application as csvFileReader.

After this, a new window of visual builder will open. Now click on the leftmost PC icon to create a new webapp. Click on + web application.

Article content

This dialog box would open after that. Now, give a name to your application as csvReader and choose Navigation style none. Click on Create.

Article content
Article content

Now, in Main flow, create a page and choose a name. In this example, we have taken main start.

In page designer, choose code view and then remove all the prebuilt html from there. Now, you have to drop a file-picker component for that you must follow these instructions:

Article content

After removing all prebuilt code your page will look something like this

Article content

Now, from the components you have to choose file-picker component and drop on the page. Just follow below instructions for the same.

Article content

Now, some code would be added in the editor just like below.

Article content

Go into design mode and click on the picker and open the properties of this component. You need not to do anything with general tabs, just go for events in the properties.

Article content

Then, a page would open similar to the one shown below, click on new Even.

Article content

You will be directed to register action chain for this component, now drag and drop call function action just like below screenshot.

Article content

After this click on JavaScript and you will be directed to scripts of the page. You have to extend a prototype function in the pageModule. Next, we are going to write a function fileReadMulti which is going to read csv file and print the output in the console.

Article content

In the function, we are returning a promise which resolve the file properties and content. Here at line 8 we are taking an instance of FileReader object which will be used to read the file.

At line 9 we are reading the file as text by the readAsText function of reader instance. Reader has various event handler as well, we have used onloadend event, we can use onload event also.

Then, we have resolved an object which contains fileId , which you can specify , file name, file size which we can calculate if required, and content.

Also, we are not using this resolved object anywhere, so for checking purpose we print the content just by stringifying it at line 19.

Article content

Now we have completed the function, we have to pass parameter to that function. So, at file parameter we have to supply a single file. We can see Fx tag at the file dialog, just click on that.

Article content

Map it through File item[0].

Article content

We can give any name to fileId.

Article content

Now the function is completed.

Article content

Let’s start testing now. Play the webapp for testing.

It will navigate you to the below page.

Article content

Click on the file-picker. You would get an option to choose the csv file. We have attached a csv file in this blog but you can choose your own.

We have chosen ConneqtionGroupRaushanBlog.csv file, this file has very little content although.

Article content
Article content

Open the inspect in google chrome, here in console the output will be printed just after choosing the file.

Article content

conneqtionGroupRaushanBlog

Here we can see the output is printed in console. If we want to do anything with that output we can do any type of Transformation.

Article content
Article content

Now, we can do any thing with data. But here we are going to show that how can we show the csv data to a table after reading the file.

Here is the whole Process:

First of all we have to make the data into array format and then we will push whole array into an ADP and then we will populate the data into a table.

You can see in below screenshot:

Just drag and drop a table component in the page.

Article content
Article content

Open the code editor and assign an id to the table as we have given “table1”.

Article content

The above code is like this:

This function accepts two parameter first one is array of lines of file in the form of strings that means the array is of string type. Second parameter is key, unique key to be passed to ADP.

Now, it will take line 1 of the file and create a header array in the form of strings.

We are creating array of objects.

Then we would need a library just like shown in below screenshot. Now we have constructor of ArrayDataProvider.

Article content
Article content

We can create new ArrayDataProvider, and we have created with name dataprovider and we are passing array of objects and key of the data.

Then we are querying the table on the basis of table id (which I have assigned as “table1”). Then we will assign data and columns to the table. This way we will be able to see the table and file content on the table.

Attachement – PageModule.prototype.

If you have any questions or concern, kindly leave a comment below or contact us on business@conneqtiongroup.com.


To view or add a comment, sign in

More articles by Conneqtion Group

Insights from the community

Others also viewed

Explore topics