cancel
Showing results for 
Search instead for 
Did you mean: 

How to access files(text files) in xsjs project using .xsjs scripting and edit them?

Former Member
0 Kudos

Hi ,

I am newbie, and i have created a xsjs project which displays data in an html page.Now i want to get the data from the tables and apply some logic,convert them to JSON and store in a text file which can be consumed by the HTML file and display in the browser.

 

JSON is a predefined file with contents which determine the structure of the HTML file.I have to fill the values in this JSON.txt  from the tables dynamically and save so that when html file is loaded the JSON have the real time values.

Are there any XS IO libraries which help in reading and writing to files in the project on the server side?

Regards,

Phani

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I don't understand why you would actually want to store the JSON as a file on the server side.  You should retrieve the data and format it as JSON in the XSJS each time you need it. If you need to persist the JSON results across multiple sessions (for instance a shopping cart), you should write it into a database table not store it in the Repository.  The Repository is for design time objects.

brenton_ocallaghan
Active Participant
0 Kudos

Completely agree with Thomas here. Once you store the data in tables you can then expose and consume that data in JSON format using the built in XSODATA concept.

You can turn the output of any OData service into JSON by adding the $format=json flag to the end of the URL. e.g. myService.xsodata/collectionName?$format=json

Brenton.