### Form Initialization and Scheduling Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Event_block.md
Shows how to extend a form to include an ON INIT handler for initial setup and an ON SCHEDULE handler for periodic actions.
```lsf
CLASS Shift;
currentShift = DATA Shift();
CLASS Cashier;
currentCashier = DATA Cashier();
CLASS Receipt;
shift = DATA Shift (Receipt);
cashier = DATA Cashier (Receipt);
FORM POS 'POS' // declaring the form for product sale to the customer in the salesroom
OBJECTS r = Receipt PANEL // adding an object that will store the current receipt
// ... declaring the behavior of the form
;
createReceipt () {
NEW r = Receipt {
shift(r) <- currentShift();
cashier(r) <- currentCashier();
ACTIVATE POS.r = r;
}
}
// extending the form with an ON INIT handler so that opening it runs createReceipt,
// which creates a new receipt and makes it the current object on the form
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();
;
```
--------------------------------
### Start lsfusion Server on Windows
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_manual.md
Use this command to start the lsfusion server as a service on Windows. Ensure the CLASSPATH includes the server JAR file.
```cmd
java -cp ".;lsfusion-server-6.2.jar" lsfusion.server.logics.BusinessLogicsBootstrap
```
--------------------------------
### Start lsfusion Server on Linux
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_manual.md
Use this command to start the lsfusion server as a service on Linux. Ensure the CLASSPATH includes the server JAR file.
```shell
java -cp ".:lsfusion-server-6.2.jar" lsfusion.server.logics.BusinessLogicsBootstrap
```
--------------------------------
### Start LSFusion Server (Windows)
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_auto.md
Use this command to start the LSFusion application server on Windows.
```shell
$INSTALL_DIR/Server/bin/lsfusion6_server.exe //ES//lsfusion6_server
```
--------------------------------
### LSF Module Header Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Module_header.md
An example demonstrating the definition of a module name, its dependencies, and its namespace, followed by class and property declarations.
```lsf
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
```
--------------------------------
### Start BLB Server
Source: https://github.com/lsfusion/platform/blob/master/AGENTS.md
Starts the lsFusion server (BusinessLogicsBootstrap). It loads .lsf modules, connects to Postgres, and exposes RMI. Requires specific JVM arguments.
```bash
lsfusion.server.logics.BusinessLogicsBootstrap
```
```bash
--add-opens=java.base/java.{util,lang}=ALL-UNNAMED
```
--------------------------------
### Activate Property for Data Entry
Source: https://github.com/lsfusion/platform/blob/master/docs/en/ACTIVATE_operator.md
This example shows how to create a new data record and immediately activate a specific property for user input. This is useful for guiding the user through data entry workflows, such as adding a new item to a receipt.
```lsf
CLASS ReceiptDetail;
barcode = DATA STRING[30] (ReceiptDetail);
quantity = DATA STRING[30] (ReceiptDetail);
FORM POS
OBJECTS d = ReceiptDetail
PROPERTIES(d) barcode, quantityGrid = quantity
;
createReceiptDetail 'Add sales line'(STRING[30] barcode) {
NEW d = ReceiptDetail {
barcode(d) <- barcode;
ACTIVATE PROPERTY POS.quantityGrid;
}
}
```
--------------------------------
### REQUEST Operator Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/REQUEST_operator.md
This example demonstrates how to use the REQUEST operator to prompt the user to choose from a list or input a value, and then handle the result.
```lsf
requestCustomer (Order o) {
LOCAL resultValue = STRING[100] ();
REQUEST {
ASK 'Choose from list?' DO
DIALOG customers OBJECTS c = resultValue() CHANGE;
ELSE
INPUT = resultValue() CHANGE;
} DO
customer(o) <- resultValue();
}
FORM request
OBJECTS o = Order
PROPERTIES(o) customer ON CHANGE requestCustomer(o) // for example, group change will be performed
;
```
--------------------------------
### Example lsFusion Query
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Frontend.md
An example of how to call the `select` function with a specific lsFusion program code string to retrieve game data. The returned data is in JSON format.
```javascript
select("date(Game g), hostTeamName(g), hostGoals(g), guestGoals(g), guestTeamName(g), resultName(g)")
```
--------------------------------
### SHOW operator example with OBJECTS and initActionOperator
Source: https://github.com/lsfusion/platform/blob/master/docs/en/SHOW_operator.md
Demonstrates opening a form with initial object values and an init action operator.
```lsf
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;
}
}
}
```
--------------------------------
### JOIN Operator Syntax Examples
Source: https://github.com/lsfusion/platform/blob/master/docs/en/JOIN_operator.md
Illustrates the basic syntax of the JOIN operator for defining properties.
```lsf
f = DATA INTEGER (INTEGER, INTEGER, INTEGER);
g = DATA INTEGER (INTEGER, INTEGER);
h = DATA INTEGER (INTEGER, INTEGER);
c(a, b) = f(g(a, b), h(b, 3), a);
```
```lsf
count = DATA BPSTRING[255] (INTEGER);
name = DATA BPSTRING[255] (INTEGER);
formatted(INTEGER a, INTEGER b) = [FORMULA BPSTRING[255] ' CAST($1 AS TEXT) || \' / \' || CAST($2 AS TEXT)'](count(a), name(b));
```
--------------------------------
### Install LSFusion 6 Server on Ubuntu/Debian
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_auto.md
Use this command to install the LSFusion 6 Server (including OpenJDK) on Ubuntu 18 or Debian 9 systems.
```shell
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-server)
```
--------------------------------
### Pivot Table Configuration Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Pivot_block.md
An example demonstrating the configuration of a pivot table within a FORM statement, including rows, columns, measures, chart type, and settings visibility.
```lsf
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)
;
```
--------------------------------
### JavaScript Example: Fetching Shipments by Date
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Frontend.md
An example of calling the `select` function to retrieve shipments for a specific date. The parameter name is flexible, only the order matters.
```javascript
select("id = Shipment s, number(s) WHERE date(s) = $1", { date: new Date().toISOString().substr(0, 10) })
```
--------------------------------
### Default Form Design Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Form_design.md
This example demonstrates the basic structure of a form with objects, properties, and filters, as generated by the default design.
```lsf
FORM myForm 'myForm'
OBJECTS myObject = myClass
PROPERTIES(myObject) myProperty1, myProperty2 PANEL
FILTERGROUP myFilter
FILTER 'myFilter' myProperty1(myObject)
;
```
--------------------------------
### Form Event Handlers Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Event_block.md
Demonstrates defining event handlers for OK and DROP events within a form.
```lsf
showImpossibleMessage() { MESSAGE 'It\'s impossible'; };
posted = DATA BOOLEAN (Invoice);
FORM invoice 'Invoice' // creating a form for editing an invoice
OBJECTS i = Invoice PANEL // creating an object of the invoice class
// ... setting the rest of the form behavior
EVENTS
// specifying that when the user clicks OK, an action should be executed
// that will execute actions to "conduction" this invoice
ON OK { posted(i) <- TRUE; },
// by clicking the formDrop button, showing a message that this cannot be,
// since this button by default will be shown only in the form for choosing an invoice,
// and this form is basically an invoice edit form
ON DROP showImpossibleMessage()
;
```
--------------------------------
### Execute user-provided code with EVAL
Source: https://github.com/lsfusion/platform/blob/master/docs/en/EVAL_operator.md
This example shows how to set up a property to receive user-entered source code and then use the EVAL operator to execute that code.
```lsf
code 'Source code' = DATA BPSTRING[2000] ();
execute 'Execute code' { EVAL code(); }
```
--------------------------------
### Install LSFusion 6 Database Server on Ubuntu/Debian
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_auto.md
Use this command to install the LSFusion 6 Database Server on Ubuntu 18+ or Debian 9+ systems.
```shell
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-db)
```
--------------------------------
### Install LSFusion 6 Client on Ubuntu/Debian
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_auto.md
Use this command to install the LSFusion 6 Client (with Tomcat 9.0.104) on Ubuntu 18 or Debian 9 systems.
```shell
source <(curl -s https://download.lsfusion.org/apt/install-lsfusion6-client)
```
--------------------------------
### Displaying Multiple Messages Sequentially with MESSAGE
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Show_message_MESSAGE_ASK.md
This example demonstrates how to display multiple messages sequentially using a loop. Each message is shown individually.
```lsf
// In this case, five text messages will be shown to the user
testMessage() {
LOCAL i = INTEGER();
i() <- 0;
WHILE i() < 5 DO {
i() <- i() + 1;
MESSAGE i();
}
}
```
--------------------------------
### Define Action Before Another Action
Source: https://github.com/lsfusion/platform/blob/master/docs/en/BEFORE_statement.md
This example shows how to define an action that will be executed before the `changeName` action. The message will be displayed each time `changeName` is called.
```lsf
changeName(Sku s, STRING[100] name) {
name(s) <- name;
}
// The message will be shown before each call to changeName
BEFORE changeName(Sku s, STRING[100] name) DO MESSAGE 'Changing user name';
```
--------------------------------
### Example Usage of Comparison Operators
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Comparison_operators.md
Demonstrates practical applications of comparison operators in defining boolean properties and logic.
```lsf
equalBarcodes = barcode(a) == barcode(b);
outOfIntervalValue1(value, left, right) = value < left OR value > right;
outOfIntervalValue2(value, left, right) = NOT (value >= left AND value <= right);
```
--------------------------------
### Displaying a Form with Date Filters
Source: https://github.com/lsfusion/platform/blob/master/docs/en/In_an_interactive_view_SHOW_DIALOG.md
Use SHOW_DIALOG to display a form with date range filters. This example initializes dateFrom and dateTo properties.
```lsf
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;
}
}
}
```
--------------------------------
### Control LSFusion Client (Windows)
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_auto.md
Manage the LSFusion web server client on Windows via command line. Stop and start the service as needed.
```shell
# Stop server
$INSTALL_DIR/Client/bin/lsfusion6_client.exe //SS//lsfusion6_client
# Start server
$INSTALL_DIR/Client/bin/lsfusion6_client.exe //ES//lsfusion6_client
```
--------------------------------
### Simple ID Examples in lsFusion
Source: https://github.com/lsfusion/platform/blob/master/docs/en/IDs.md
Simple IDs are basic identifiers consisting of letters, digits, and underscores, starting with a letter. They are used for naming system elements and parameters.
```lsf
name
value_id13
bankAccount
```
--------------------------------
### EXPAND UP Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/EXPAND_operator.md
Demonstrates expanding a specific element and its ancestors up the object tree using the EXPAND UP operator. Requires a form definition with a tree structure.
```lsf
expandUp {
EXPAND UP expandCollapseTest.e OBJECTS e = navigatorElementCanonicalName('System.administration');
}
```
--------------------------------
### LSFusion Server Action to Listen on Port
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_INTERNAL.md
Defines a server-side action to listen on a specified port and process incoming messages. This example uses LSFusion script to create a message class, define a received message handler, and initiate listening on a port when the server starts. It requires the Apache Mina library to be in the server's classpath.
```lsf
CLASS Message;
text 'Text' = DATA STRING (Message);
receivedMessage (STRING str) {
NEW m = Message {
text(m) <- str;
}
APPLY;
}
listenPort INTERNAL 'ListenPort' (STRING, INTEGER);
onStarted() + {
listenPort('localhost', 9999);
}
```
--------------------------------
### HTTP GET Request
Source: https://github.com/lsfusion/platform/blob/master/docs/en/EXTERNAL_operator.md
Perform an HTTP GET request and save the response to a file.
```lsf
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
```
--------------------------------
### Basic Window Creation
Source: https://github.com/lsfusion/platform/blob/master/docs/en/WINDOW_statement.md
Demonstrates the creation of system windows with specific positioning, alignment, and styling options.
```lsf
WINDOW logo HORIZONTAL POSITION(0, 0, 10, 6) VALIGN(CENTER) HALIGN(START) HIDETITLE HIDESCROLLBARS CLASS logoWindowClass();
```
```lsf
WINDOW root HORIZONTAL POSITION(10, 0, 70, 6) VALIGN(CENTER) HALIGN(CENTER) HIDETITLE HIDESCROLLBARS CLASS rootWindowClass();
```
```lsf
WINDOW system HORIZONTAL POSITION(80, 0, 20, 6) VALIGN(CENTER) HALIGN(END) HIDETITLE HIDESCROLLBARS CLASS systemWindowClass();
```
--------------------------------
### Write File Examples
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Write_file_WRITE.md
Demonstrates writing files to different destinations using the WRITE operator. Includes writing to a file path, writing from the client, and writing with a client-side dialog.
```lsf
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';
}
}
```
--------------------------------
### Get Orders by Date
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Retrieves a list of order numbers for a specified date via an HTTP GET request.
```APIDOC
## getOrdersByDate (DATE d)
### Description
Fetches a list of order numbers associated with a given date.
### Method
GET
### Endpoint
`http://localhost:7651/exec?action=Location.getOrdersByDate`
### Parameters
#### Query Parameters
- **p** (DATE) - Required - The date for which to retrieve orders (e.g., `12.11.2018`).
### Request Example
`http://localhost:7651/exec?action=Location.getOrdersByDate&p=12.11.2018`
### Response
#### Success Response (200)
- **order** (Array of Objects) - A list of orders, each containing an 'nm' property (order number).
- **nm** (string) - The order number.
#### Response Example
```json
{
"order": [
{
"nm": "42"
},
{
"nm": "65"
}
]
}
```
```
--------------------------------
### Example XML Output
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Data_export.md
This is an example of the XML structure generated from the LSFusion form definition, showcasing nested tags and attributes.
```xml
13.11.18
12
Customer2
Address2
Book2
1
3.99
Book1
2
4.99
```
--------------------------------
### Launch Desktop Client with JAR
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Execution_manual.md
Use this command to launch the LSFusion desktop client from a JAR file. Ensure the working directory is set to the directory containing the downloaded client JAR.
```shell
java -jar lsfusion-client-6.2.jar
```
--------------------------------
### Example JSON Payload for Creating a City
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
This is an example of the JSON payload that is sent in the HTTP request body when creating a new city.
```json
{"countryId":"123","name":"San Francisco"}
```
--------------------------------
### Launch lsFusion Platform with Docker Compose
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Docker.md
Start the lsFusion platform containers (PostgreSQL, Application Server, Web Client) by running this command in the directory containing your `compose.yaml` file. The web client will be accessible at http://localhost:8080/.
```bash
docker-compose up -d
```
--------------------------------
### ABSTRACT LIST sequential implementations
Source: https://github.com/lsfusion/platform/blob/master/docs/en/ABSTRACT_action_operator.md
Provides two sequential implementations for the 'onStarted' abstract action. The first logs 'Preparing data', and the second logs 'Starting handlers'.
```lsf
onStarted () + {
MESSAGE 'Preparing data';
}
```
```lsf
onStarted () + {
MESSAGE 'Starting handlers';
}
```
--------------------------------
### Build Docker Image for lsFusion Project (Install Phase)
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Docker.md
Builds the Docker image for your lsFusion project and loads it into the local Docker storage. This command activates the `assemble` and `docker` Maven profiles.
```bash
mvn install -P assemble,docker
```
--------------------------------
### Declare and Call Actions with EXEC
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Call_EXEC.md
Demonstrates declaring an action with parameters, another action that calls it, and how to use the EXEC operator. Also shows capturing a result from an action into a property.
```lsf
importData(Sku sku, Order order) {
MESSAGE 'Run import for ' + id(sku) + ' ' + customer(order);
}
order = DATA Order (OrderDetail) NONULL DELETE;
// declaration of the action runImport that calls importData
runImport(OrderDetail d) { importData(sku(d), order(d)); }
// calling an action with a result and writing it into a property
getPrice (Item i) ABSTRACT NUMERIC[10,2];
currentPrice = DATA LOCAL NUMERIC[10,2] ();
showPrice (Item i) {
getPrice(i) TO currentPrice;
MESSAGE 'Price: ' + currentPrice();
}
```
--------------------------------
### Build GWT Web Client
Source: https://github.com/lsfusion/platform/blob/master/AGENTS.md
Compiles the GWT web client. Use -q for quiet output.
```bash
mvn -pl web-client gwt:compile -q
```
--------------------------------
### Example JSON Data Structure
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Frontend.md
An example of the JSON data structure returned from the server, containing game and team lists, along with current selections.
```json
{
"game":{
"list":[
{
"date":"05.02.19",
"hostGoals":3,
"guestTeamName":"New York Rangers",
"hostTeamName":"Detroit Red Wings",
"guestGoals":2,
"value":6054,
"resultName":"ПО"
},
{
"date":"13.02.19",
"hostGoals":2,
"guestTeamName":"Toronto Maple Leafs",
"hostTeamName":"Montreal Canadiens",
"guestGoals":0,
"value":6063,
"resultName":"П"
},
{
"date":"15.02.19",
"hostGoals":3,
"guestTeamName":"Montreal Canadiens",
"hostTeamName":"New York Rangers",
"guestGoals":5,
"value":6072,
"resultName":"П"
},
{
"date":"17.02.19",
"hostGoals":2,
"guestTeamName":"Detroit Red Wings",
"hostTeamName":"Toronto Maple Leafs",
"guestGoals":1,
"value":6075,
"resultName":"ПБ"
}
],
"value":6054
},
"team":{
"list":[
{
"gamesLostSO":0,
"goalsConceded":3,
"gamesLostOT":0,
"goalsScored":7,
"gamesWon":2,
"points":6,
"gamesWonOT":0,
"gamesLost":0,
"gamesPlayed":2,
"name":"Montreal Canadiens",
"gamesWonSO":0,
"place":1,
"value":6064
},
{
"gamesLostSO":1,
"goalsConceded":4,
"gamesLostOT":0,
"goalsScored":4,
"gamesWon":0,
"points":3,
"gamesWonOT":1,
"gamesLost":0,
"gamesPlayed":2,
"name":"Detroit Red Wings",
"gamesWonSO":0,
"place":2,
"value":6057
},
{
"gamesLostSO":0,
"goalsConceded":3,
"gamesLostOT":0,
"goalsScored":2,
"gamesWon":0,
"points":2,
"gamesWonOT":0,
"gamesLost":1,
"gamesPlayed":2,
"name":"Toronto Maple Leafs",
"gamesWonSO":1,
"place":3,
"value":10993
},
{
"gamesLostSO":0,
"goalsConceded":8,
"gamesLostOT":1,
"goalsScored":5,
"gamesWon":0,
"points":1,
"gamesWonOT":0,
"gamesLost":1,
"gamesPlayed":2,
"name":"New York Rangers",
"gamesWonSO":0,
"place":4,
"value":6061
}
],
"value":6064
}
}
```
--------------------------------
### Example Error Response from HTTP Request
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
This JSON structure represents an error response from the HTTP endpoint, for example, if an invalid country code is provided.
```json
{"code":"1","message":"Invalid country code"}
```
--------------------------------
### Basic NEWSESSION Usage
Source: https://github.com/lsfusion/platform/blob/master/docs/en/NEWSESSION_operator.md
Demonstrates creating a new session to add a Currency object and then applying changes. This is a basic example of encapsulating an action within a new session.
```lsf
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[Currency]) {
// 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;
}
}
}
```
--------------------------------
### Create and Access Structures with STRUCT and []
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Structure_operators_STRUCT.md
Demonstrates the creation of structures using the STRUCT operator and accessing elements using the [] operator. The first example shows basic structure creation, while the second illustrates accessing a specific attachment from a structure.
```lsf
objectStruct(a, b) = STRUCT(a, f(b));
stringStruct() = STRUCT(1, 'two', 3.0);
```
```lsf
CLASS Letter;
attachment1 = DATA FILE (Letter);
attachment2 = DATA FILE (Letter);
letterAttachments (Letter l) = STRUCT(attachment1(l), attachment2(l));
secondAttachment(Letter l) = letterAttachments(l)[2]; // returns attachment2
```
--------------------------------
### READ Operator Examples
Source: https://github.com/lsfusion/platform/blob/master/docs/en/READ_operator.md
Demonstrates reading files from different protocols including HTTP, HTTPS, FTP, FTPS, SFTP, and local file paths into a property. Ensure the target property is of a file class.
```lsf
readFiles() {
LOCAL importFile = FILE ();
//reading from HTTP
READ 'http://www.lsfusion.org/file.xlsx' TO importFile;
//reading from HTTPS
READ 'https://www.lsfusion.org/file.xlsx' TO importFile;
//reading from FTP
READ 'ftp://ftp.lsfusion.org/file.xlsx' TO importFile;
//reading from FTPS
READ 'ftps://ftps.lsfusion.org/file.xlsx' TO importFile;
//reading from SFTP
READ 'sftp://sftp.lsfusion.org/file.xlsx' TO importFile;
//reading from FILE
READ 'D://lsfusion/file.xlsx' TO importFile;
READ 'file://D://lsfusion/file.xlsx' TO importFile;
}
```
--------------------------------
### Create Matrix Form with Grouped Columns and Highlighting
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Matrix.md
This example demonstrates how to group related columns (e.g., price and delay) for each buyer and apply background highlighting to specific data cells. It also shows how to filter which buyers are displayed.
```lsf
selected 'Mark' = DATA BOOLEAN (Customer);
headerName 'Price header' (Customer c) = name(c) + ': Price';
headerGrace 'Dealy header' (Customer c) = name(c) + ': Delay, days';
FORM pricesAndGracePeriods 'Prices and delays'
OBJECTS s = Customer
PROPERTIES selected(s), name(s) READONLY
OBJECTS c = Customer
FILTERS selected(c)
OBJECTS b = Book
PROPERTIES name(b) READONLY,
price(b, c) COLUMNS 'priceAndGrace' (c) HEADER headerName(c),
gracePeriod(b, c) COLUMNS 'priceAndGrace' (c) HEADER headerGrace(c)
;
DESIGN pricesAndGracePeriods {
BOX(b) {
fill = 3;
PROPERTY(gracePeriod(b, c)) {
background = #FFFFAA;
}
}
}
```
--------------------------------
### External HTTP GET and POST Requests
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Access_to_an_external_system_EXTERNAL.md
Demonstrates making GET requests to retrieve a file and POST requests with JSON data. Note that JSON braces are escaped.
```lsf
externalHTTP() {
// GET request with a single file result
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
open(exportFile());
// POST with a JSON body parameter; braces are escaped because of internationalization
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=getExamples'
PARAMS JSONFILE('\{"mode"=1\}')
TO exportFile;
IMPORT FROM exportFile() FIELDS () TEXT caption, TEXT code DO
MESSAGE 'Example : ' + caption + ', code : ' + code;
}
```
--------------------------------
### Start Headless Chrome for UI Verification
Source: https://github.com/lsfusion/platform/blob/master/AGENTS.md
Launches a headless Chrome instance for UI testing. Persistent user data directories can maintain login states across sessions.
```bash
google-chrome --headless=new --remote-debugging-port=9333 \
--user-data-dir=/tmp/chrome-profile-headless --window-size=1280,800 &
```
--------------------------------
### Export Orders by Date via HTTP GET
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Retrieves a list of order numbers for a specified date using an HTTP GET request. The date is passed as a parameter in the URL.
```lsf
FORM exportOrders
OBJECTS date = DATE PANEL
OBJECTS order = Order
PROPERTIES nm = number(order)
FILTERS date(order) = date
;
getOrdersByDate (DATE d) {
EXPORT exportOrders OBJECTS date = d JSON;
}
```
--------------------------------
### Deploy Docker Image to Registry (Deploy Phase)
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Docker.md
Assembles the Docker image for your lsFusion project and uploads it to a public registry like Docker Hub. This command activates the `assemble` and `docker` Maven profiles.
```bash
mvn deploy -P assemble,docker
```
--------------------------------
### Initialize JS and CSS files on web client init
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Custom_components_properties.md
This code snippet demonstrates how to load custom JavaScript and CSS files when the web client initializes. Files are added to the 'onWebClientInit' property with a specified loading order.
```lsf
onWebClientInit() + {
onWebClientInit('chat.js') <- 1;
onWebClientInit('chat.css') <- 2;
}
```
--------------------------------
### Export Order Attachments via HTTP GET
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Retrieves order parameters and a list of attached files for a given order ID via an HTTP GET request. The order ID is passed as a URL parameter.
```lsf
FORM orderAttachments
OBJECTS o = Order
PROPERTIES(o) number, date
OBJECTS attachments = Attachment
PROPERTIES id = VALUE(attachments), name(attachments)
;
getOrderAttachments (LONG orderId) {
FOR LONG(Order o AS Order) = orderId DO {
EXPORT orderAttachments OBJECTS o = o JSON;
}
}
```
--------------------------------
### Retrieve Specific File Content via HTTP GET
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Provides an action to retrieve the content of a specific file using its internal identifier via an HTTP GET request. The Content-Type header is set based on the file extension.
```lsf
getOrderAttachment (LONG id) {
FOR LONG(Attachment a AS Attachment) = id DO
exportFile() <- file(a);
}
```
--------------------------------
### Build Multi-Architecture Docker Image (Deploy Phase)
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Docker.md
Builds a multi-architecture Docker image (linux/amd64 and linux/arm64) for your lsFusion project. This profile is only available during the `deploy` phase and requires the `assemble`, `docker`, and `multiarch` Maven profiles.
```bash
mvn deploy -P assemble,docker,multiarch
```
--------------------------------
### Delete Object Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Class_change_CHANGECLASS_DELETE.md
Demonstrates how to delete a specific object using the DELETE operator.
```lsf
deleteObject(obj) { DELETE obj; }
```
--------------------------------
### Get Order Attachments
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Retrieves the parameters and a list of attached files for a given order identifier.
```APIDOC
## getOrderAttachments (LONG orderId)
### Description
Retrieves order details and a list of its attachments based on the order's internal identifier.
### Method
GET
### Endpoint
`http://localhost:7651/exec?action=getOrderAttachments`
### Parameters
#### Query Parameters
- **p** (LONG) - Required - The internal identifier of the order.
### Request Example
`http://localhost:7651/exec?action=getOrderAttachments&p=32178`
### Response
#### Success Response (200)
- **date** (string) - The date of the order.
- **number** (string) - The order number.
- **attachments** (Array of Objects) - A list of attachments associated with the order.
- **name** (string) - The name of the attachment.
- **id** (LONG) - The internal identifier of the attachment file.
#### Response Example
```json
{
"date": "20.10.2021",
"number": "12",
"attachments": [
{
"name": "File 1",
"id": 32180
},
{
"name": "File 2",
"id": 32183
}
]
}
```
```
--------------------------------
### Migration Script Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Migration.md
This script demonstrates various migration changes including property renaming, class renaming, object renaming, and table renaming. Use this to update your system when refactoring or moving elements.
```script
V0.3.1 {
STORED PROPERTY Item.gender[Item.Article] -> Item.dataGender[Item.Article] // change of DATA property
PROPERTY System.SIDProperty[Reflection.Property] -> Reflection.dbNameProperty[Reflection.Property] // parallel transferring to another namespace and changing of the property name
FORM PROPERTY Item.itemForm.name(i) -> Item.itemForm.itemName(i)
}
V0.4 {
FORM PROPERTY Document.documentForm.name(i) -> Document.itemForm.itemName(i)
FORM PROPERTY Item.itemForm.itemName(i) -> Item.itemForm.iname // adding of an explicit name for a property on a formе: iname = itemName(i)
CLASS Date.DateInterval -> Date.Interval
OBJECT Geo.Direction.North -> Geo.Direction.north
TABLE User.oldTable -> User.newTable
}
```
--------------------------------
### FORM statement form options
Source: https://github.com/lsfusion/platform/blob/master/docs/en/FORM_statement.md
Examples of form options that can be specified after the form name and caption.
```lsfusion
imageSetting
LOCALASYNC
```
--------------------------------
### Stock Accounting Navigator Setup
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Materials_management.md
Sets up the navigator for the Stock Accounting module, organizing master data folders for items, stocks, and legal entities.
```lsf
MODULE StockAccounting;
REQUIRE Stock, Item, LegalEntity, Receipt, Shipment, StockItem;
NAVIGATOR {
NEW FOLDER masterData 'Directories' FIRST WINDOW toolbar {
NEW items;
NEW stocks;
NEW legalEntities;
}
;
```
--------------------------------
### Get Specific Attachment Content
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Interaction_via_HTTP_protocol.md
Retrieves the content of a specific file attachment using its internal identifier.
```APIDOC
## getOrderAttachment (LONG id)
### Description
Retrieves the content of a specific file attachment using its unique internal identifier.
### Method
GET
### Endpoint
`http://localhost:7651/exec?action=getOrderAttachment`
### Parameters
#### Query Parameters
- **p** (LONG) - Required - The internal identifier of the attachment file.
### Request Example
`http://localhost:7651/exec?action=getOrderAttachment&p=32180`
### Response
#### Success Response (200)
- **File Content** - The content of the file. The `Content-Type` header will correspond to the file's extension.
```
--------------------------------
### Iterate and Create Objects
Source: https://github.com/lsfusion/platform/blob/master/docs/en/New_object_NEW.md
Illustrates various loop constructs and object creation patterns, including iterating over collections, iterating with conditions, and creating new objects within loops.
```lsf
name = DATA STRING[100] (Store);
testFor {
LOCAL sum = INTEGER ();
FOR iterate(i, 1, 100) DO {
sum() <- sum() (+) i;
}
FOR in(Sku s) DO {
MESSAGE 'Sku ' + id(s) + ' was selected';
}
FOR Store st IS Store DO { // iterating over all objects of the Store class
FOR in(st, Sku s) DO { // iterating over all Sku for which in is set
MESSAGE 'There is Sku ' + id(s) + ' in store ' + name(st);
}
}
}
newSku () {
NEW s = Sku {
id(s) <- 425;
name(s) <- 'New Sku';
}
}
copy (Sku old) {
NEW new = Sku {
id(new) <- id(old);
name(new) <- name(old);
}
}
createDetails (Order o) {
FOR in(Sku s) NEW d = OrderDetail DO {
order(d) <- o;
sku(d) <- s;
}
}
```
--------------------------------
### Full Name Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Naming.md
Illustrates the format of a full name, which concatenates the namespace name with the element name.
```plaintext
.
Item.name
Sale.Document
```
--------------------------------
### FOR loop iterating over objects
Source: https://github.com/lsfusion/platform/blob/master/docs/en/FOR_operator.md
Iterates over all Sku objects in the system. This is a basic example of iterating through a collection of objects.
```lsf
FOR in(Sku s) DO {
MESSAGE 'Sku ' + id(s) + ' was selected';
}
```
--------------------------------
### External LSF Action Call
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Access_to_an_external_system_EXTERNAL.md
Example of calling a remote LSF action on another LSFusion server.
```lsf
externalLSF() {
EXTERNAL LSF 'http://localhost:7651' EXEC 'System.testAction[]';
}
```
--------------------------------
### LSFusion Arithmetic Operations
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Arithmetic_operators.md
Examples demonstrating the use of standard and specialized arithmetic operators in LSFusion for calculations.
```lsf
sum(a, b) = a + b;
transform(a, b, c) = -a * (b (+) c);
```
--------------------------------
### Example of Property Declaration with Common Parameters
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Properties_and_actions_block.md
Demonstrates how to declare properties 'date' and 'Order.number' using common parameters, resulting in property names 'd' and 'number(o)'.
```lsfusion
FORM order
OBJECTS o=Order
PROPERTIES(o) d=date, Order.number;
```
--------------------------------
### Jasper Report Template
Source: https://github.com/lsfusion/platform/blob/master/docs/en/How-to_Reports.md
This is an example of a Jasper Report XML template. It defines styles, fields, and groups for the report.
```xml
```
--------------------------------
### Aggregation Expansion Example
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Aggregations.md
This code demonstrates the unrolled expansion of aggregation logic, showing how event handlers for setting and dropping aggregated properties translate into object creation and deletion.
```lsf
prm1 = DATA class1 (aggrClass);
prm2 = DATA class2 (aggrClass);
result = GROUP AGGR aggrClass aggrObject BY prm1(aggrObject), prm2(aggrObject);
// if aggrExpr becomes non-null, create an object of class aggrClass (equivalent to aggrExpr => result(prm1, prm2) RESOLVE LEFT)
WHEN SET(aggrExpr) AND NOT result(prm1, prm2)
NEW aggrObject = aggrClass {
prm1(aggrObject) <- prm1;
prm2(aggrObject) <- prm2;
}
// if aggrExpr becomes null, remove an object (equivalent to aggrClass aggrObject IS aggrClass => result(prm1(aggrObject),prm2(aggrObject)) RESOLVE RIGHT)
WHEN aggrClass aggrObject IS aggrClass AND DROPPED(result(prm1(aggrObject),prm2(aggrObject))) DO
DELETE aggrObject;
```
--------------------------------
### Abstract List Method with Multiple Implementations
Source: https://github.com/lsfusion/platform/blob/master/docs/en/Action_extension.md
Defines an abstract list method 'onStarted' for the 'Sku' class. Two concrete implementations are provided, with the second one overriding the first.
```lsf
CLASS Sku;
name = DATA STRING[100] (Sku);
onStarted ABSTRACT LIST ();
onStarted () + {
name(Sku s) <- '1';
}
onStarted () + {
name(Sku s) <- '2';
}
```
--------------------------------
### ROUND Operator Examples
Source: https://github.com/lsfusion/platform/blob/master/docs/en/ROUND_operator.md
Demonstrates rounding a number to the nearest integer, to two decimal places, and to the nearest hundred.
```lsf
number = DATA NUMERIC[10,3](); //12345.678
rounded = ROUND(number()); //12346
rounded1 = ROUND(number(), 2); //12345.68
rounded2 = ROUND(number(), -2); //12300
FORM roundTest
PROPERTIES() number, rounded, rounded1, rounded2;
```
--------------------------------
### Create a Basic Table
Source: https://github.com/lsfusion/platform/blob/master/docs/en/TABLE_statement.md
Declares a new table named 'book' with 'Book' as its key class.
```lsf
TABLE book (Book);
```