Skip to content

Script Examples

Reading data from File

Download ZIP File

In this example, we created a UI that reads data from a CSV file.

To make it work, place the PlayerInfo.csv file on the server at the following location: C:\ProgramData\Erizos\Studio Server\Resources
This is the default directory from which the UI accesses file resources at runtime.

The script:

  • reads the file,
  • splits its content by rows,
  • stores the values in an array.

These values are then assigned to the corresponding text fields to display the data dynamically.

Locator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
const file = await File.read("PlayerInfo.csv");
const [header, ...rows] = file.split('\r\n');
const val = [];
for (const row of rows) {
  dropdown1.addItem(row.split(',').at(0));
  val.push(row.split(','));
}


dropdown1.onChange = () =>{
  FirstName_TI.value = val[dropdown1.selectedIndex][0];
  Age_TI.value = val[dropdown1.selectedIndex][1];
  Position_TI.value = val[dropdown1.selectedIndex][2];
  Height_TI.value = val[dropdown1.selectedIndex][3];
  PlayerImage_Media.value = val[dropdown1.selectedIndex][4];
};