### HTTP GET and POST Examples
Source: https://docs.lsfusion.org/v6/EXTERNAL_operator
Demonstrates fetching data from a URL using HTTP GET and sending JSON data with HTTP POST. Note that braces in JSON parameters are escaped.
```lsfusion
testExportFile = DATA FILE ();
externalHTTP() {
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
open(exportFile());
// braces are escaped as they are used in internationalization
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=getExamples'
PARAMS JSONFILE('{"mode"=1,"locale"="en"}') TO exportFile;
IMPORT FROM exportFile() FIELDS () TEXT caption, TEXT code DO
MESSAGE 'Example : ' + caption + ', code : ' + code;
// passes the second and third parameters to BODY url-encoded
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=doSomething&someprm=$1'
BODYURL 'otherprm=$2&andonemore=$3' PARAMS 1,2,'3';
}
```
--------------------------------
### Install lsFusion 6 Server & Client on Ubuntu/Debian
Source: https://docs.lsfusion.org/Execution_auto
Use this command to install lsFusion 6 Server and Client on Ubuntu 18+ or Debian 9+ systems. It sources a script that handles OpenJDK, PostgreSQL, and Tomcat setup.
```bash
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6)
```
--------------------------------
### Example conf/settings.properties for lsFusion
Source: https://docs.lsfusion.org/v6/Launch_parameters
This example shows how to configure database and RMI settings in the conf/settings.properties file. Ensure the file is placed in the application server's startup folder.
```properties
db.server=localhost
db.name=lsfusion
db.user=postgres
db.password=pswrd
rmi.port=7652
```
--------------------------------
### CHANGEKEY Example with Mode Options
Source: https://docs.lsfusion.org/v6/Action_options
Example demonstrating how to set a keyboard shortcut with specific execution conditions. This example sets Ctrl+Shift+A as the shortcut, with a priority of 100, and specifies that it should only execute when in a dialog window and when the action is currently being edited.
```plaintext
CHANGEKEY "Ctrl+Shift+A;(priority=100;dialog=only;editing=only)"
```
--------------------------------
### Install lsFusion 6 Server & Client on RHEL/CentOS/Fedora
Source: https://docs.lsfusion.org/Execution_auto
Use this command to install lsFusion 6 Server and Client on RHEL 8+, CentOS 8+, or Fedora 35+ systems. It sources a script that handles OpenJDK, PostgreSQL, and Tomcat setup.
```bash
source <(curl -s https://download.lsfusion.org/dnf/install-lsfusion6)
```
--------------------------------
### SQL Export and Import Example
Source: https://docs.lsfusion.org/v6/EXTERNAL_operator
Shows how to export data to a SQL database and then import data back from it. This example retrieves product barcodes and then updates their prices.
```lsfusion
externalSQL () {
// getting all barcodes of products with the name meat
EXPORT TABLE FROM bc=barcode(Article a) WHERE name(a) LIKE '%Meat%';
// reading prices for read barcodes
EXTERNAL SQL 'jdbc:mysql://$1/test?user=root&password='
EXEC 'select price AS pc, articles.barcode AS brc from $2 x JOIN articles ON x.bc=articles.barcode'
PARAMS 'localhost', exportFile()
TO exportFile;
// writing prices for all products with received barcodes
LOCAL price = INTEGER (INTEGER);
LOCAL barcode = STRING[30] (INTEGER);
IMPORT FROM exportFile() TO price=pc,barcode=brc;
FOR barcode(Article a) = barcode(INTEGER i) DO
price(a) <- price(i);
}
```
--------------------------------
### Start LSFusion Application Server on Linux
Source: https://docs.lsfusion.org/Execution_manual
Command to start the LSFusion application server as a service on Linux. Ensure the CLASSPATH includes the server JAR file.
```bash
java -cp ".:lsfusion-server-6.2.jar" lsfusion.server.logics.BusinessLogicsBootstrap
```
--------------------------------
### Start LSFusion Application Server on Windows
Source: https://docs.lsfusion.org/Execution_manual
Command to start the LSFusion application server on Windows. Ensure the CLASSPATH includes the server JAR file.
```cmd
java -cp ".;lsfusion-server-6.2.jar" lsfusion.server.logics.BusinessLogicsBootstrap
```
--------------------------------
### Static Object ID Examples in lsFusion
Source: https://docs.lsfusion.org/IDs
Examples demonstrating how to reference static objects within classes.
```lsfusion
Direction.north
```
```lsfusion
System.FormResult.ok
```
--------------------------------
### Start lsFusion 6 Server (Windows Command Line)
Source: https://docs.lsfusion.org/Execution_auto
Command to start the lsFusion 6 Application Server service on Windows.
```cmd
$INSTALL_DIR/Server/bin/lsfusion6_server.exe //ES//lsfusion6_server
```
--------------------------------
### Install Certbot and Generate Certificate
Source: https://docs.lsfusion.org/Execution_auto
Install Certbot and use it to obtain a standalone SSL certificate for your domain.
```bash
apt install certbot
```
```bash
certbot certonly --standalone -d myaddress.com
```
--------------------------------
### HTTP GET Request and File Import
Source: https://docs.lsfusion.org/v6/Access_to_an_external_system_EXTERNAL
Demonstrates making an HTTP GET request to fetch a file and then opening it. It also shows how to make an HTTP request with JSON parameters and import data from the response.
```lsfusion
testExportFile = DATA FILE ();
externalHTTP() {
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
open(exportFile());
// braces are escaped as they are used in internationalization
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=getExamples'
PARAMS JSONFILE('{"mode"=1,"locale"="en"}')
TO exportFile;
IMPORT FROM exportFile() FIELDS () TEXT caption, TEXT code DO
MESSAGE 'Example : ' + caption + ', code : ' + code;
// passes the second and third parameters to BODY url-encoded
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=doSomething&someprm=$1'
BODYURL 'otherprm=$2&andonemore=$3'
PARAMS 1,2,'3';
}
```
--------------------------------
### Install Application Server (lsFusion 6 Server) on Ubuntu/Debian
Source: https://docs.lsfusion.org/Execution_auto
Use this command to install the lsFusion 6 Application Server, including OpenJDK, on Ubuntu 18 or Debian 9.
```bash
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-server)
```
--------------------------------
### Aggregate function examples
Source: https://docs.lsfusion.org/Set_operations
Demonstrates the usage of GROUP SUM with a finite set and potential errors with infinite sets. Includes examples of successful execution and platform errors.
```lsfusion
CLASS A;
d = DATA INTEGER (A);
f (b) = GROUP SUM 1 IF d(a) < b;
messageF { MESSAGE f(5); } // will be executed successfully
g = GROUP SUM f(b);
messageG { MESSAGE g(); } // f(b) is not NULL for infinite set b, the platform will throw an error
FORM f
OBJECTS d=DATE
;
printFWithD { PRINT f OBJECTS d=currentDate(); } // will be executed successfully
// there is no filter for dates, and d IS DATE is not NULL for an infinite set d, the platform will throw an error
printFWithoutD { PRINT f; }
```
--------------------------------
### Install Database Server (PostgreSQL) on Ubuntu/Debian
Source: https://docs.lsfusion.org/Execution_auto
Use this command to install the lsFusion 6 Database Server (PostgreSQL) on Ubuntu 18+ or Debian 9+.
```bash
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-db)
```
--------------------------------
### CHANGEMOUSE Example with SHOW Option
Source: https://docs.lsfusion.org/v6/Action_options
Example of setting a double-click mouse event as a trigger for an action, with the condition that the mouse click should be displayed in the action header.
```plaintext
CHANGEMOUSE DBLCLK SHOW
```
--------------------------------
### Example Pivot Table Configuration
Source: https://docs.lsfusion.org/v6/Pivot_block
A complete example demonstrating the usage of the PIVOT block to configure columns, rows, measures, and options for a pivot table within a FORM statement.
```lsfusion
FORM PivotTest
OBJECTS s = Store
PROPERTIES(s) name, storeSizeCode, storeSizeName, storeSizeFullName
PIVOT s 'Bar Chart' NOSETTINGS MAX
ROWS (name(s), MEASURES(s)) COLUMNS storeSizeName(s), storeSizeFullName(s) MEASURES storeSizeCode(s)
;
```
--------------------------------
### Install Web Server (lsFusion 6 Client) on Ubuntu/Debian
Source: https://docs.lsfusion.org/Execution_auto
Use this command to install the lsFusion 6 Web Server (Client), including Tomcat 9.0.104, on Ubuntu 18 or Debian 9.
```bash
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-client)
```
--------------------------------
### Example lsFusion Query
Source: https://docs.lsfusion.org/How-to_Frontend
This is an example of a script that can be passed to the select function to retrieve specific game data from the lsFusion backend. The EXPORT FROM operator is implicitly handled by the select function.
```javascript
select("date(Game g), hostTeamName(g), hostGoals(g), guestGoals(g), guestTeamName(g), resultName(g)")
```
--------------------------------
### ACTION Statement Examples
Source: https://docs.lsfusion.org/v6/ACTION_statement
Illustrates basic declarations of actions using the ACTION statement. The first example shows a simple action with a message, while the second demonstrates an action with a caption and an abstract parameter.
```lsfusion
showMessage { MESSAGE 'Hello World!'; } // action declaration
```
```lsfusion
loadImage 'Upload image' ABSTRACT ( Item);
```
--------------------------------
### Example Java Startup Option
Source: https://docs.lsfusion.org/Launch_parameters
Set the `logics.topModule` parameter directly in Java startup options using the `-D` prefix.
```bash
-Dlogics.topModule=FFF
```
--------------------------------
### Example Module Header with Class and Property Definition
Source: https://docs.lsfusion.org/v6/Module_header
Illustrates a complete module header with module name, dependencies, namespace, and subsequent class and property definitions.
```lsfusion
MODULE EmployeeExample;
REQUIRE System, Utils;
NAMESPACE Employee;
CLASS Employee 'Employee';
CLASS Position 'Position';
employeePosition(employee) = DATA Position (Employee);
```
--------------------------------
### SCHEDULE PERIOD Statement Example
Source: https://docs.lsfusion.org/NAVIGATOR_statement
Demonstrates how to schedule an action to run periodically, with an option to fix the period count from the action's start time.
```plaintext
SCHEDULE PERIOD intPeriod [FIXED] action;
```
--------------------------------
### Example Module Header
Source: https://docs.lsfusion.org/Module_header
Illustrates a complete module header with module name, dependencies, namespace, and class/property definitions.
```lsfusion
MODULE EmployeeExample;
REQUIRE System, Utils;
NAMESPACE Employee;
CLASS Employee 'Employee';
CLASS Position 'Position';
employeePosition(employee) = DATA Position (Employee);
```
--------------------------------
### Define Book and Tag Classes
Source: https://docs.lsfusion.org/v6/How-to_GROUP_CONCAT
Defines the 'Book' and 'Tag' classes with their respective properties and the 'in' relationship between them. This setup is required for the subsequent GROUP CONCAT example.
```lsfusion
CLASS Book 'Book';
CLASS Tag 'Tag';
name 'Name' = DATA ISTRING[10] (Tag);
in 'On' = DATA BOOLEAN (Tag, Book);
```
--------------------------------
### Simple ID Examples in lsFusion
Source: https://docs.lsfusion.org/IDs
Simple IDs are basic identifiers consisting of letters, digits, and underscores, starting with a letter. They are used for naming system elements and parameters.
```lsfusion
name
```
```lsfusion
value_id13
```
```lsfusion
bankAccount
```
--------------------------------
### Basic NEWSESSION Example
Source: https://docs.lsfusion.org/v6/NEWSESSION_operator
Demonstrates creating a new Currency object in a new session and applying the changes. The object will be present in the database after the session closes.
```lsfusion
testNewSession () {
NEWSESSION {
NEW c = Currency {
name(c) <- 'USD';
code(c) <- 866;
}
APPLY;
}
// here a new object of class Currency is already in the database
LOCAL local = BPSTRING[10] (Currency);
local(Currency c) <- 'Local';
NEWSESSION {
MESSAGE (GROUP SUM 1 IF local(Currency c) == 'Local'); // will return NULL
}
NEWSESSION NESTED (local) {
// will return the number of objects of class Currency
MESSAGE (GROUP SUM 1 IF local(Currency c) == 'Local');
}
NEWSESSION {
NEW s = Sku {
id(s) <- 1234;
name(s) <- 'New Sku';
SHOW sku OBJECTS s = s;
}
}
}
```
--------------------------------
### Define Book and Category Classes
Source: https://docs.lsfusion.org/How-to_IF_CASE
Defines the data structures for Book and Category, including their properties like name, category, and price. This setup is required for the subsequent examples.
```lsfusion
CLASS Book 'Book';
name 'Name' = DATA ISTRING[50] (Book);
CLASS Category 'Category' {
novel 'Novel',
thriller 'Thriller',
fiction 'Fiction'
}
category 'Category' = DATA Category (Book);
price 'Price' = DATA NUMERIC[14,2] (Book);
```
--------------------------------
### Start/Stop Application Server (lsfusion6_client)
Source: https://docs.lsfusion.org/Execution_auto
Use these commands to start or stop the LSFusion application server using its client executable.
```bash
$INSTALL_DIR/Client/bin/lsfusion6_client.exe //SS//lsfusion6_client
```
```bash
$INSTALL_DIR/Client/bin/lsfusion6_client.exe //ES//lsfusion6_client
```
--------------------------------
### Number Order Lines with PARTITION SUM
Source: https://docs.lsfusion.org/How-to_PARTITION
Use PARTITION SUM to number order lines sequentially starting from 1 as they are added. This example sorts by the internal ID of lines within an order.
```lsfusion
CLASS Order 'Order';
CLASS OrderDetail 'Order line';
order 'Order' = DATA Order (OrderDetail) NONULL DELETE;
```
```lsfusion
index 'Line number' (OrderDetail d) = PARTITION SUM 1 ORDER d BY order(d) CHARWIDTH 4;
```
--------------------------------
### Define Book and Category Data Structures
Source: https://docs.lsfusion.org/How-to_Reports
Defines the data model for categories and books, including relationships and a method to get the category name for a book. This setup is necessary before creating report forms.
```lsfusion
NAMESPACE Sample;
CLASS Category 'Category';
name 'Name' = DATA ISTRING[50] (Category) IN id;
CLASS Book 'Book';
name 'Name' = DATA ISTRING[100] (Book) IN id;
category 'Category' = DATA Category (Book) AUTOSET;
nameCategory 'Category' (Book b) = name(category(b)) IN id;
countBooks 'Number of books' (Category c) = GROUP SUM 1 BY category(Book b);
FORM books 'Books'
OBJECTS b = Book
PROPERTIES(b) READONLY name, nameCategory
PROPERTIES(b) NEWSESSION NEW, EDIT, DELETE
;
NAVIGATOR {
NEW books;
}
```
--------------------------------
### Show Form Example
Source: https://docs.lsfusion.org/In_an_interactive_view_SHOW_DIALOG
Demonstrates opening a form with specified date ranges and within a new session. The form is displayed as a floating window.
```lsfusion
date = DATA DATE (Order);
FORM showForm
OBJECTS dateFrom = DATE, dateTo = DATE PANEL
PROPERTIES VALUE(dateFrom), VALUE(dateTo)
OBJECTS o = Order
FILTERS date(o) >= dateFrom, date(o) <= dateTo
;
testShow () {
SHOW showForm OBJECTS dateFrom = 2010_01_01, dateTo = 2010_12_31;
NEWSESSION {
NEW s = Sku {
SHOW sku OBJECTS s = s FLOAT;
}
}
}
```
--------------------------------
### Example XML Output
Source: https://docs.lsfusion.org/How-to_Data_export
This is an example of the XML structure generated from the defined form.
```xml
13.11.18
12
Customer2
Address2
Book2
1
3.99
Book1
2
4.99
```
--------------------------------
### SHOW Operator Example with Object Initialization and Nested Session
Source: https://docs.lsfusion.org/SHOW_operator
Demonstrates opening a form with initial object values, a nested session, and an inline initialization action.
```lsfusion
date = DATA DATE (Order);
FORM showForm
OBJECTS dateFrom = DATE, dateTo = DATE PANEL
PROPERTIES VALUE(dateFrom), VALUE(dateTo)
OBJECTS o = Order
FILTERS date(o) >= dateFrom, date(o) <= dateTo
;
testShow () {
SHOW showForm OBJECTS dateFrom = 2010_01_01, dateTo = 2010_12_31 { MESSAGE 'On init'; };
NEWSESSION {
NEW s = Sku {
SHOW sku OBJECTS s = s FLOAT;
}
}
}
```
--------------------------------
### EMAIL Operator Examples
Source: https://docs.lsfusion.org/EMAIL_operator
Illustrative examples of how to use the EMAIL operator in different scenarios.
```APIDOC
## EMAIL Operator Examples
### Example 1: Sending a login reminder email
```
FORM remindUserPass
OBJECTS u=CustomUser PANEL
PROPERTIES(u) READONLY login, name[Contact]
;
emailUserPassUser 'Login reminder' (CustomUser user) {
LOCAL bodyFile = FILE ();
PRINT remindUserPass OBJECTS u = user HTML TO bodyFile;
EMAIL
SUBJECT 'Login reminder'
TO email(user)
BODY bodyFile()
NOWAIT
;
}
```
### Example 2: Sending a simple email with a body from a file
```
justSendEmail 'Send letter' () {
stringToFile('big red text');
EMAIL
FROM 'luxsoft@adsl.by'
SUBJECT 'Letter subject'
TO 'xxx@tut.by'
BODY resultFile()
;
}
```
```
--------------------------------
### Define a Module with Dependencies and Classes
Source: https://docs.lsfusion.org/v6/Modules
This example demonstrates how to define a module named 'EmployeeExample', specify its dependencies on 'System' and 'Utils' modules, set its namespace to 'Employee', and declare two classes, 'Employee' and 'Position', along with a property 'employeePosition'.
```lsfusion
MODULE EmployeeExample; // Defining the module name
REQUIRE System, Utils; // Listing the modules that the Employee module depends on
NAMESPACE Employee; // Setting the namespace
CLASS Employee 'Employee'; // Creating a class
CLASS Position 'Position'; // Creating another class
employeePosition(employee) = DATA Position (Employee); // Creating property
```
--------------------------------
### Enable API via Java startup parameters
Source: https://docs.lsfusion.org/MCP_server
Use Java startup parameters to set the `enableAPI` system property. A value of `1` permits authenticated API access.
```bash
-Dsettings.enableAPI=1
```
--------------------------------
### Composite ID Examples in lsFusion
Source: https://docs.lsfusion.org/IDs
Examples of composite IDs, including those with and without a specified namespace.
```lsfusion
System.name
```
```lsfusion
Sale.Document
```
```lsfusion
name
```
--------------------------------
### Implement Abstract LIST Action
Source: https://docs.lsfusion.org/v6/ACTION_plus_statement
Demonstrates implementing an abstract LIST action 'onStarted' with two separate implementations. Both implementations are executed sequentially.
```lsfusion
onStarted ABSTRACT LIST ( );
onStarted () + {
name(Sku s) <- '1';
}
onStarted () + {
name(Sku s) <- '2';
}
// first, the 1st action is executed, then the 2nd action
```
--------------------------------
### Example: Copying Order Properties with {...}
Source: https://docs.lsfusion.org/Braces_operator
Demonstrates how to use the {...} operator to create a new action that sequentially copies currency and customer data from an old order to a new one. Local properties are scoped to the operator.
```lsfusion
CLASS Currency;
name = DATA STRING[30] (Currency);
code = DATA INTEGER (Currency);
CLASS Order;
currency = DATA Currency (Order);
customer = DATA STRING[100] (Order);
copy 'Copy' (Order old) {
NEW new = Order { // an action is created that consists of the sequential execution of two actions
currency(new) <- currency(old); // a semicolon is put after each statement
customer(new) <- customer(old);
} // there is no semicolon in this line, because the operator ends in }
}
```
--------------------------------
### Typed Parameter Examples in lsFusion
Source: https://docs.lsfusion.org/IDs
Examples of typed parameters, showing usage with and without explicit class IDs.
```lsfusion
user
```
```lsfusion
User user
```
```lsfusion
System.User user
```
```lsfusion
INTEGER count
```
--------------------------------
### Create a basic TABLE statement
Source: https://docs.lsfusion.org/TABLE_statement
This example demonstrates the basic syntax for creating a table named 'book' with a single key class 'Book'.
```lsfusion
TABLE book (Book);
```
--------------------------------
### Property/Action Canonical Name Examples
Source: https://docs.lsfusion.org/v6/Naming
Provides specific examples of canonical names for properties and actions with different parameter types.
```plaintext
Item.gender[Item.Article]
Date.between[DATE,DATE,DATE]
Document.addHeader[Document.Document,STRING]
Math.sum[?,?]
```
--------------------------------
### Using Dialogs for Selection and Input
Source: https://docs.lsfusion.org/Interactive_view
Demonstrates how to use dialogs for selecting a SKU and for changing a SKU associated with an order detail. It includes examples of both input and change modes for dialogs.
```lsfusion
FORM selectSku
OBJECTS s = Sku
PROPERTIES(s) id
;
testDialog {
DIALOG selectSku OBJECTS s INPUT DO {
MESSAGE 'Selected sku : ' + id(s);
}
}
sku = DATA Sku (OrderDetail);
idSku (OrderDetail d) = id(sku(d));
changeSku (OrderDetail d) {
DIALOG selectSku OBJECTS s = sku(d) CHANGE;
//equivalent to the first option
DIALOG selectSku OBJECTS s = sku(d) INPUT NULL CONSTRAINTFILTER DO {
sku(d) <- s;
}
}
```
--------------------------------
### Property or Action on a Form ID Examples in lsFusion
Source: https://docs.lsfusion.org/IDs
Examples of IDs used for properties or actions directly associated with a form.
```lsfusion
barcodeSku.amount(b)
```
```lsfusion
Item.items.name(i)
```
```lsfusion
Consignment.dashboard.date
```
--------------------------------
### Example JSON Payload for City Creation
Source: https://docs.lsfusion.org/v6/How-to_Interaction_via_HTTP_protocol
This is an example of the JSON payload that is generated and sent in the HTTP request body for creating a city.
```json
{"countryId":"123","name":"San Francisco"}
```
--------------------------------
### Expand Up Example
Source: https://docs.lsfusion.org/v6/EXPAND_operator
This example shows how to expand elements upwards, including ancestors. It targets a specific navigator element by its canonical name.
```javascript
FORM expandCollapseTest
TREE elements e = NavigatorElement PARENT parent(e)
PROPERTIES(e) READONLY BACKGROUND NOT e IS NavigatorFolder VALUE, canonicalName, caption
;
expandUp {
EXPAND UP expandCollapseTest.e OBJECTS e = navigatorElementCanonicalName('System.administration');
}
EXTEND FORM expandCollapseTest
PROPERTIES() expandUp
;
```
--------------------------------
### Write File Action Example
Source: https://docs.lsfusion.org/Write_file_WRITE
Demonstrates how to use the WRITE operator to save a file to different destinations. Supports appending and writing from the client.
```lsfusion
loadAndWrite () {
INPUT f = FILE DO {
WRITE f TO 'file:///home/user/loadedfile.csv' APPEND;
WRITE CLIENT f TO '/home/user/loadedfile.txt';
WRITE CLIENT DIALOG f TO 'loadedfile';
}
}
```
--------------------------------
### Create a full TABLE statement
Source: https://docs.lsfusion.org/TABLE_statement
This example demonstrates creating a 'full' table named 'sku' with 'Sku' as its key class. A 'full' table includes all objects belonging to the key classes.
```lsfusion
TABLE sku (Sku) FULL;
```
--------------------------------
### Expand Down Example
Source: https://docs.lsfusion.org/v6/EXPAND_operator
This example demonstrates expanding elements downwards in the object tree. It targets a specific navigator element by its canonical name.
```javascript
FORM expandCollapseTest
TREE elements e = NavigatorElement PARENT parent(e)
PROPERTIES(e) READONLY BACKGROUND NOT e IS NavigatorFolder VALUE, canonicalName, caption
;
expandDown {
EXPAND DOWN expandCollapseTest.e OBJECTS e = navigatorElementCanonicalName('System.administration');
}
EXTEND FORM expandCollapseTest
PROPERTIES() expandDown
;
```
--------------------------------
### Define Report Hierarchy Example
Source: https://docs.lsfusion.org/Print_view
Example of defining a form structure with object groups and properties, illustrating potential report hierarchy.
```lsfusion
FORM myForm 'myForm'
OBJECTS A, B SUBREPORT, C, D, E
PROPERTIES f(B, C), g(A, C)
FILTERS c(E) = C, h(B, D)
;
```
--------------------------------
### Define and Execute Sequential Actions
Source: https://docs.lsfusion.org/Sequence
Demonstrates defining classes and then creating an action that copies data sequentially. It also shows how to load default currencies and run a sequence of these loads.
```lsfusion
CLASS Currency;
name = DATA STRING[30] (Currency);
code = DATA INTEGER (Currency);
CLASS Order;
currency = DATA Currency (Order);
customer = DATA STRING[100] (Order);
copy 'Copy' (Order old) {
// an action is created that consists of the sequential execution of two actions
NEW new = Order {
currency(new) <- currency(old); // a semicolon is put after each statement
customer(new) <- customer(old);
} // there is no semicolon in this line, because the operator ends in }
}
loadDefaultCurrency(ISTRING[30] name, INTEGER code) {
NEW c = Currency {
name(c) <- name;
code(c) <- code;
}
}
run () {
loadDefaultCurrency('USD', 866);
loadDefaultCurrency('EUR', 1251);
}
```
--------------------------------
### Non-Materializable Property Example
Source: https://docs.lsfusion.org/Materializations
This example demonstrates a property that cannot be materialized because it is not NULL for an infinite number of dates. Such properties require re-calculation on each read.
```lsfusion
// such a property cannot be materialized, since it is not NULL for an infinite number of dates
lastDate(Customer customer, DATE date) = GROUP LAST date(Order order) IF customer(order) = customer AND date(order) < date ORDER order;
```
--------------------------------
### HTTP GET Request with File Export
Source: https://docs.lsfusion.org/EXTERNAL_operator
Performs an HTTP GET request and saves the response to a file. Useful for downloading resources.
```lsfusion
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
```
--------------------------------
### HTTP GET Request with File Result
Source: https://docs.lsfusion.org/Access_to_an_external_system_EXTERNAL
Performs an HTTP GET request to fetch a file. The result is stored in exportFile and then opened.
```lsFusion
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
open(exportFile());
```
--------------------------------
### Start/Stop Application Server (systemctl)
Source: https://docs.lsfusion.org/Execution_auto
Manage the LSFusion application server service using systemctl commands on Linux.
```bash
systemctl stop lsfusion6-server
```
```bash
systemctl start lsfusion6-server
```
--------------------------------
### Form Initialization and Scheduling Event Handlers
Source: https://docs.lsfusion.org/Event_block
Demonstrates setting up event handlers for form initialization (INIT) and scheduled periodic actions. The INIT handler runs when the form opens, and the SCHEDULE handler executes at a defined interval.
```lsfusion
EXTEND FORM POS
EVENTS
// when opening the form, executing the action to create a new receipt,
// which fills in the shift, cashier and other information
ON INIT createReceipt()
//apply every 60 seconds
ON SCHEDULE PERIOD 60 FIXED apply();
```
--------------------------------
### OVERRIDE Operator Examples
Source: https://docs.lsfusion.org/OVERRIDE_operator
Demonstrates using the OVERRIDE operator to select values from different properties. The first example defines `overMarkup` which selects between a book's markup and its group's markup. The second example, `notNullDate`, provides a default date if the input date is NULL.
```lsfusion
CLASS Group;
markup = DATA NUMERIC[8,2] (Group);
markup = DATA NUMERIC[8,2] (Book);
group = DATA Group (Book);
overMarkup (Book b) = OVERRIDE markup(b), markup(group(b));
notNullDate (INTEGER i) = OVERRIDE date(i), 2010_01_01;
```
--------------------------------
### Create System Windows
Source: https://docs.lsfusion.org/WINDOW_statement
Example of creating system windows with specific orientations, positions, alignments, and hidden titles/scrollbars.
```javascript
WINDOW logo HORIZONTAL POSITION(0, 0, 10, 6) VALIGN(CENTER) HALIGN(START) HIDETITLE HIDESCROLLBARS CLASS logoWindowClass();
WINDOW root HORIZONTAL POSITION(10, 0, 70, 6) VALIGN(CENTER) HALIGN(CENTER) HIDETITLE HIDESCROLLBARS CLASS rootWindowClass();
WINDOW system HORIZONTAL POSITION(80, 0, 20, 6) VALIGN(CENTER) HALIGN(END) HIDETITLE HIDESCROLLBARS CLASS systemWindowClass();
WINDOW toolbar VERTICAL POSITION(0, 6, 20, 94) HIDETITLE CLASS toolbarWindowClass();
```
--------------------------------
### Example JSON Response for City Creation
Source: https://docs.lsfusion.org/v6/How-to_Interaction_via_HTTP_protocol
These are example JSON responses that can be received from the server after attempting to create a city, indicating success or failure.
```json
{"code":"0","message":"OK"}
```
```json
{"code":"1","message":"Invalid country code"}
```
--------------------------------
### Launch lsFusion Platform with Docker Compose
Source: https://docs.lsfusion.org/Docker
Start the lsFusion platform containers (PostgreSQL, Application Server, Web client) by running this command in the directory containing your compose.yaml file.
```bash
docker-compose up -d
```
--------------------------------
### Example JSON message data
Source: https://docs.lsfusion.org/v6/How-to_Custom_components_properties
An example of a JSON object representing a single chat message, conforming to the structure defined by the JSON operator.
```json
{
"author":"John Doe",
"time":"2021-10-05T15:28:05",
"text":"Hello, Jack!",
"own":1,
"replyAuthor":"Jack Smith",
"replyText":"Hello, John",
"replyMessage":31302
}
```
--------------------------------
### Get Order Attachment Content
Source: https://docs.lsfusion.org/v6/How-to_Interaction_via_HTTP_protocol
Retrieves the content of a specific file attachment using its internal identifier via an HTTP GET request.
```APIDOC
## getOrderAttachment (LONG id)
### Description
Retrieves the content of a specific file attachment.
### Method
GET
### Endpoint
http://localhost:7651/exec?action=getOrderAttachment
### Parameters
#### Query Parameters
- **p** (LONG) - Required - The internal identifier of the file.
### Response
#### Success Response (200)
- The content of the file. The `Content-Type` header will correspond to the file's extension.
```
--------------------------------
### Start/Stop Web Server (Client) (systemctl)
Source: https://docs.lsfusion.org/Execution_auto
Control the LSFusion web server (client) service with systemctl commands on Linux.
```bash
systemctl stop lsfusion6-client
```
```bash
systemctl start lsfusion6-client
```
--------------------------------
### Expand All Top Example
Source: https://docs.lsfusion.org/v6/EXPAND_operator
This example demonstrates recursively expanding all top-level elements within a specified object group. The OBJECTS block is ignored in this case.
```javascript
FORM expandCollapseTest
TREE elements e = NavigatorElement PARENT parent(e)
PROPERTIES(e) READONLY BACKGROUND NOT e IS NavigatorFolder VALUE, canonicalName, caption
;
expandAllTop {
EXPAND ALL TOP expandCollapseTest.e;
}
EXTEND FORM expandCollapseTest
PROPERTIES() expandAllTop
;
```