Define Rows as maps: var row = { "column1": "field1", "column2": "field2" }
Add Rows to Table: use SuiteTable's addRow method: SuiteTable.addRow(table, row);
// create a new tablevartable=SuiteTable.create("MyTable");// add columns to tableSuiteTable.addStringColumn(table,"Name");SuiteTable.addIntColumn(table,"age");SuiteTable.addInstantColumn(table,"joined");SuiteTable.addDateTimeColumn(table,"birthday");SuiteTable.addBooleanColumn(table,"customer");// define two rowsvarrow1={"Name":"tony","age":20,"joined":Instant.now(),"birthday":LocalDate.now(),"customer":true};varrow2={"Name":"Mark","age":20,"joined":Instant.parse("2023-10-20T12:00:00Z"),"birthday":LocalDate.of(2023,10,24),"customer":false};// add rows to tableSuiteTable.addRow(table,row1);SuiteTable.addRow(table,row2);returntable;
Adding Columns
Adding a column to a table is done with a single methods: add<type>Column.
Note: The columns appear in the table in the order they were added.
ColumnTypes supported: String, Intger, Double, Boolean, Instant, DateTime, Date, Time, and Instant.
Add a StringColumn with the specified name to a Table instance.
Parameters:
columnName (Type: String) - The name of the StringColumn.
table (Type: Table) - Instance of Table.
Example:
AddIntColumn(columnName: String): void
Add an IntColumn with the specified name to a Table instance.
Parameters:
columnName (Type: String) - The name of the IntColumn.
table (Type: Table) - Instance of Table.
Example:
addDoubleColumn(columnName: String): void
Add a DoubleColumn with the specified name to a Table instance.
Parameters:
columnName (Type: String) - The name of the DoubleColumn.
table (Type: Table) - Instance of Table.
Example:
Similarly for the rest of the ColumnTypes.
Adding Rows
Note: The rows appear in the table in the order they were added.
To add row, you first need to have already created an instance of Class Table and at least one column. Then you can define a row a time as follows: A hashmap with column title and row value
Then, you can add the row to your table using the addRow method:
Add a row of data to the table instance and return the row.
Parameters:
row (Type: HashMap<String, Object>) - A map representing the data to be added to the row.
table (Type: Table) - Instance of Table.
Example:
Table Information
Methods for retreiving table information such as table name, column names, list of rows.
name(): String
Get the name of the table.
Returns:
A String representing the name of the table.
Example:
columnNames(): List<String>
Get the list of column names in the table.
Returns:
A List<String> representing the column names.
Example:
columnCount(): Integer
Get the number of columns in the table.
Returns:
An Integer representing the total number of columns in the table.
Example:
Note: Replace placeholder content with actual information related to your SuiteTableclass. Feel free to add more details or examples based on your specific use cases.
rowCount(): Integer
Get the number of rows in the table.
Returns:
An Integer representing the total number of rows in the table.
Example:
Note: Replace placeholder content with actual information related to your SuiteTable class. Feel free to add more details or examples based on your specific use cases.
columnIndex(columnName: String): Integer - Returns the index of a column by name.
row(rowIndex: Integer): Row - Returns the Row object at the specified index.
where(selection: Selection): Table - Returns a new table containing rows that match the selection criteria.
stringColumn(columnIndex: Integer): StringColumn - Returns a StringColumn for the specified column.
first(nRows: Integer): Table - Returns a new table containing the first nRows of data.
last(nRows: Integer): Table - Returns a new table containing the last nRows of data.
inRange(rowStart: Integer, rowEnd: Integer): Table - Returns a new table containing rows within the specified range.
sortOn(columnIndex: Integer): Table - Sorts the table based on the specified column index.
removeColumns(...columnIndex: Integer[]): Table - Removes specified columns from the table.
emptyCopy(): Table - Returns a table with the same columns but no data.
sampleX(proportion: Double): Table - Returns a table with a sample based on the given proportion.
sampleN(nRows: Integer): Table - Returns a table with a random sample of the specified number of rows.
summary(): Table - Returns a table containing summary statistics for the columns in the relation.
var table = SuiteTable.create("MyTable");
SuiteTable.addStringColumn(table, "key"); // column index 0
SuiteTable.addDoubleColumn(table, "rate"); // column index 1
SuiteTable.addStringColumn(table, "lastUpdate"); // column iondex 2
// Specify the column name you want to find the index for
var columnIndex = table.columnIndex("rate");
// Get the index of the column by name
var columnIndex = originalTable.columnIndex(columnNameToFind);
// columnIndex is 1
var rowIndex = 3; // Example index
var row = table.row(rowIndex);
var selection = table.stringColumn("Name").isEqualTo("Alice");
var filteredTable = table.where(selection);
return filteredTable;
// filteredTable now has one row: Alice: 25
// Specify the index of the column for which you want to get a StringColumn
var columnIndex = 3; // Replace with the actual index
// Get the StringColumn for the specified column index
var stringColumn = originalTable.stringColumn(columnIndex);
var first10Rows = table.first(10);
// Specify the number of rows you want to retrieve from the end
var nRows = 5; // Replace with the actual number of rows you need
// Get a new table containing the last nRows of data
var lastTable = originalTable.last(nRows);
// Specify the range of rows you want to extract
var rowStart = 2; // Replace with the actual starting row index
var rowEnd = 6; // Replace with the actual ending row index
// Get a new table containing rows within the specified range
var rangeTable = originalTable.inRange(rowStart, rowEnd);
var sortedTable = table.sortOn(columnIndex);
var columnsToRemove = [1, 3]; // Example column indices to remove
var modifiedTable = table.removeColumns(...columnsToRemove);
var emptyCopy = table.emptyCopy();
var proportion = 0.2; // Example proportion
var sampledTable = table.sampleX(proportion);
var numRowsToSample = 5; // Example number of rows to sample
var sampledTable = table.sampleN(numRowsToSample);
var summaryTable = table.summary();
// Retrieve exchange rates from the API
var request = HttpUtil.get("https://boi.org.il/PublicApi/GetExchangeRates");
var jsonContent = JsonUtil.parse(request.asString().getBody());
var exchanges = jsonContent.get('exchangeRates');
// Create a table to store the data
var table = SuiteTable.create("MyTable");
SuiteTable.addStringColumn(table, "key");
SuiteTable.addDoubleColumn(table, "rate");
SuiteTable.addDateTimeColumn(table, "lastUpdate");
// Populate the table with data from the API
for (var i = 0; i < exchanges.size(); i++) {
var item = exchanges.get(i);
var key = item.get('key').asText();
var rate = item.get('currentExchangeRate').asDouble();
var instant = Instant.parse(item.get('lastUpdate').asText());
var date = LocalDateTimeUtil.fromInstant(instant);
var row = {
"key": key,
"rate": rate,
"lastUpdate": date
};
SuiteTable.addRow(table, row);
}
// Filter table with some type of selection
var selection = table.stringColumn("key").isEqualTo("USD");
var filteredTable = table.where(selection);
// Return the filtered table
return filteredTable;