<<  Overview
Contents
  1. Records, Page Contents
  2. Helper
  3. Read/Write
  4. Files
  5. Advanced

Records, Page Contents

Record, Records

Record RECORD

Record currently openedList<Value> values = RECORD.getValues(); Or: Record record = RECORD;
List<Value> values = record.getValues();

List<Record> RECORDS

Records of current view// Records in loop
List<Record> records = RECORDS;
for(Record record : records) {
}

Values

Read values

Reading the values of a records (visible values in table or all values)// Visible columns/values
List<Value> values = record.getValues();
for(Value value : values) {
    String name = value.getName(); // Technical Name
    String text = value.getText(); // Display Text
    String obj = value.getObject(); // Java-Object (String, Long, Double, Date, Boolean)
}
More contents:// All columns/values
List<Value> values = record.getValuesAll();
// Single value
Value value = record.getValue("country");

String color = record.getBackgroundColor();
List<Annotation> annotations = record.getAnnotations();
// Subtables (Contents: tables.title, tables.records, tables.columns)
List<Table> tables = record.getTables();
// Attachments
List<Attachment> attachments = record.getAttachments();

Grouping, Page

Grouping of page

List<Group> groups = PAGE.getGroups();
for(Group group : groups) {
    // Also Title/Level/Count: group.title, group.level, group.count
    List<Column> columns = group.getColumns();
    List<Record> records = group.getRecords();

    for(Column column : columns) {
        String name = column.getName();
        String label = column.getLabel();
    }
}

Current page

PAGE.isView: Is view with records
PAGE.isRecord: Is record opened
PAGE.isWebserver: Application is running in Webserver
PAGE.title: Title of current pageif (PAGE.isRecord) {
}
if (PAGE.isView) {
}
if (PAGE.isWebserver) {
}
String title = PAGE.title;

Helper

Templates/Return

Read template

Allows to read a text file, useful if content should be added to a existing file. Templates are read from:
scripts/templates/ (Predefined or your own application)// Read template
String templateContent = TEMPLATE.read("HTML_Template1.html");

// Perform replacements (Example)
String page = templateContent.replace("%CONTENT%", "MY CONTENT").replace("%PAGE_TITLE%", PAGE.title);

Return value

// Script provides a return value
RESULT.set("Sum for year: xx");
// Append text to return value; set() not necessary for append()
RESULT.append("\nSum for month: xx");

Escape/Format

Escape for special characters

// Replaces special characters e.g. <, >
ESCAPE.forHtml(String text)
ESCAPE.forXml(String text)
ESCAPE.forJson(String text)
ESCAPE.forJava(String text)

HTML-Output

// Creates HTML-Code for the parameters (also images)
HTML.toHtml(Value value)
HTML.toHtml(String text)
HTML.toHtml(List<Annotation> annotationsList)
HTML.toHtml(Annotation annotation)
HTML.toHtml(Attachment attachment)

Object Information

toString() for objects and variables

Objects and variables provide information to the content and available methods using toString()// Examples for toString()
String summary = "";

summary += RECORD.toString()+"\n";
summary += RECORDS.toString()+"\n";
summary += PAGE.toString()+"\n";

summary += TEMPLATE.toString()+"\n";
summary += RESULT.toString()+"\n";

summary += READ.toString()+"\n";
summary += WRITE.toString()+"\n";

summary += UPLOADS.toString()+"\n";
summary += FILE.toString()+"\n";

RESULT.set(summary);

Read/Write

Read/Change

Reading records

// Reads all records of the table named by the parameter
// The records only contain values, no further details (Annotations, Subtables, ...)
List<Record> recordsWithValues = READ.getRecords(String tablename);

Change values

// Apply new value
WRITE.setValue(Record record, String fieldname, String newValue);

Create/Delete

Insert empty record

// Add new record
Record newRecord = WRITE.insertNewRecord(String tablename);

Insert record

// Add new record
String tablename = "...";
Record record = new Record(tablename);
record.setValue("firstname", "theodora");

WRITE.insertRecord(record);

Delete record

// Delete a record
Record myrecord = RECORD;
WRITE.deleteRecord(myrecord);
WRITE.deleteRecordLogical(myrecord); // Delete Logical
Or:// Delete record, set using Tablename, ID
String tablename = "...";
Long id = 1122;

Record record = new Record(tablename, id);
WRITE.deleteRecord(record);

Files

Fields, Uploads

Fields

// Read bytes of field value
byte[] bytes = FILE.readBytes(Value value);
// Read bytes of upload
byte[] bytes = FILE.readBytes("file.txt");
// Read multiple files
List<byte[]> filesBytes = FILE.readBytesList(Value value);

Add Uploads

UPLOADS.add("file.txt", String text);
UPLOADS.add("file.bin", byte[] bytes);

File Access

Temp-Files, Open/Edit

// Temp Files
File tmp = FILE.temp();
File tmp = FILE.temp(String ending);
File tmp = FILE.temp(String ending, String prefix);

// Open/Edit/Browse in Operating System (not Webserver)
FILE.open(File file);
FILE.edit(File file);
FILE.browse(String url);

File System

FILE.write(File file, String text);
FILE.write(File file, byte[] bytes);

String filetext = FILE.read(File file);
byte[] bytes = FILE.readBytes(File file);

Advanced

Java-Classes

Classes in scripts

Scripts allow to define own classes.
Variablen to use in scripts are only available outside of Java-Classes. Because of this they need to be provided in the constructor, an example:// Variables PAGE, ESCAPE, UTIL, RESULT, ... are only available outside classes
// Solution: Use variable SCRIPT as parameter, it contains all other variables
new Demo(SCRIPT);

public class Demo {
    private Script s;

    public Demo(Script script) {
        this.s = script;

        // Now available:
        // s.PAGE
        // s.ESCAPE
        // s.UTIL
        // s.RESULT
        // s.RECORD
        // s.RECORDS
        // ...

        execute();
    }

    private void execute() {
        s.RESULT.set("My Result");
    }
}
Variables: RECORD, RECORDS, PAGE, ESCAPE, UTIL, TEMPLATE, FILE, HTML, READ, WRITE, RESULT, UPLOADS

Template-Example

Read template, fill content and write to file

Fills a new template and writes it to a temporary file. Then the file is opened in the system.
// Read template and replace placeholders
String content = "MY CONTENT";

String templateContent = TEMPLATE.read("TEMPLATE_HERE.html");
String page = templateContent.replace("%CONTENT%", content).replace("%PAGE_TITLE%", PAGE.title);

// Temp File
File file = FILE.temp(".html");

// Write to file
FILE.write(file, page);

// Open file in System
FILE.open(file);