EXPORT operator
The EXPORT operator: creates an action that exports specified properties to a file, or, in common case, that opens a form in a structured view.
Syntax
EXPORT [exportFormat] FROM [columnId1 =] propertyExpr1, ..., [columnIdN = ] propertyExprN [WHERE whereExpr] [ORDER orderExpr1 [DESC], ..., orderExprL [DESC]] [TOP n] [TO propertyId]
EXPORT formName [OBJECTS objName1 = expr1, ..., objNameK = exprK] [exportFormat] [TOP n] [TO (propertyId | (groupId1 = propertyId1, ..., groupIdN = propertyIdM))]
exportFormat can be specified by one of the following options:
JSON [CHARSET charsetStr]
XML [HEADER | NOHEADER] [ATTR] [CHARSET charsetStr]
CSV [separator] [HEADER | NOHEADER] [ESCAPE | NOESCAPE] [CHARSET charsetStr]
XLS [SHEET sheetProperty] [HEADER | NOHEADER]
XLSX [SHEET sheetProperty] [HEADER | NOHEADER]
DBF [CHARSET charsetStr]
TABLE
Description
The EXPORT operator creates an action that exports data from the specified properties or form to a file. The following file formats are supported: XML, JSON, CSV, XLS, XLSX, DBF, TABLE.
If no export file format is specified, it is considered to be JSON.
If the property to which the data is exported is of class FILE, then the extension of the resulting file is determined depending on the format as follows:
| Format | Extension |
|---|---|
| JSON | json |
| XML | xml |
| CSV | csv |
| XLS | xls |
| XLSX | xlsx |
| DBF | dbf |
| TABLE | table |
When exporting a form in an OBJECTS block, it is possible to add extra filters to check for the equality of the objects on the form with the values passed. These objects will not participate in building the object group hierarchy.
Parameters
Source of export
-
formNameThe name of the form from which you want to export data. Composite ID.
-
objName1 ... objNameKNames of form objects for which filtered (fixed) values are specified. Simple IDs.
-
expr1 ... exprKExpressions whose values determine the filtered (fixed) values for form objects.
-
propertyExpr1, ..., propertyExprNList of expressions from whose values the data is exported. Each property is mapped to a table column of the result file.
-
columnId1, ..., columnIdNA list of column IDs in the resulting file into which data from the corresponding property will be exported. Each list element is either a simple ID or a string literal. If no ID is specified, it is considered equal to
expr<Column number>by default. -
whereExprAn expression whose value is a condition for the export. If not specified, it is considered equal to the disjunction of all exported properties (that is, at least one of the properties must be non-
NULL). -
orderExpr1, ..., orderExprLList of expressions by which the exported data is sorted. Only properties present in the list
propertyExpr1, ..., propertyExprNcan be used -
DESCKeyword. Specifies reverse sort order. By default, ascending sort is used.
Export format
-
ATTRA keyword that specifies that values should be exported to the attributes of the parent tag. If not specified, the values are exported to child tags. Only applicable for export to XML.
-
separatorDelimiter in a CSV file. String literal. If not specified, then the default delimiter is
;. -
HEADER | NOHEADERKeywords specifying the presence (
HEADER) or absence (NOHEADER) of a header string in a CSV, XLS, or XLSX file. The default isNOHEADER.When using the
NOHEADERoption if the column name is one of the predefined names (A,B, ...,Z,AA, ...,AE), it is exported to the column with the corresponding number, and the following columns are exported to the columns next in order after this column.Has other meaning for XML: with
HEADERresult file contains first string like<?xml version="1.0" encoding="UTF-8"?>. Export withNOHEADERexports without this string. The default isHEADER. -
ESCAPE | NOESCAPEKeywords specifying the presence (
ESCAPE) or absence (NOESCAPE) of escaping for special characters (\r,\n,"(double quotes) and the specified delimiter (separator) in a CSV file. It makes sense to useNOESCAPEonly in cases where the specified delimiter is guaranteed not to occur in the data. The default isESCAPE. -
CHARSET charsetStrAn option specifying the encoding used for export.
-
charsetStrString literal that defines the encoding. Default value for
JSON,XML,CSVisUTF-8, forDBFisCP1251.
-
-
sheetPropertyThe ID of the property whose value is used as the name of the sheet in the exported file. The property must not have parameters. It is used for
XLSandXLSXexport formats. -
TOP nExports only the first
nrecords. Integer literal.
Export destination
-
propertyIdProperty ID to which the generated file will be written. This property must not have parameters and its value must be of a file class (
FILE,RAWFILE,JSONFILE, etc.). If this property is not specified, theSystem.exportFileproperty is used by default. -
groupId1, ..., groupIdMNames of object groups from the exported form for which you want to export data. Simple IDs. Used only for exporting forms to flat formats.
-
propertyId1 , ..., propertyIdMProperty IDs to which the generated files for specified object groups will be written. These properties must not have parameters and their value must be of file classes (
FILE,RAWFILE,JSONFILE, etc.). Used only for exporting forms to flat formats. For the empty group of objects, the namerootis used.
Examples
CLASS Store;
name = DATA STRING[20] (Sku);
weight = DATA NUMERIC[10,2] (Sku);
in = DATA BOOLEAN (Store, Sku);
exportSkus (Store store) {
// uploading to DBF all Sku for which in (Store, Sku) is specified for the desired warehouse
EXPORT DBF CHARSET 'CP866' FROM id(Sku s), name(s), weight(s) WHERE in(store, s);
// uploads to CSV without header line and escaping special characters
EXPORT CSV NOHEADER NOESCAPE FROM id(Sku s), name(s), weight(s) WHERE in(store, s);
// uploads JSON, sorting by property name[Sku] in descending order
EXPORT FROM id(Sku s), name(s), weight(s) WHERE in(store, s) ORDER name(s) DESC;
// uploads JSON {"ff":"HI"}, as by default it gets the name value, and the platform
// gets the object {"value":"HI"} to "HI"
EXPORT FROM ff='HI';
// uploads JSON "HI", as by default it gets the name value, and the platform
// automatically converts the object {"value": "HI"} to "HI"
EXPORT FROM 'HI';
}
FORM exportSku
OBJECTS st = Store
OBJECTS s = Sku
PROPERTIES(s) id, name, weight
FILTERS in(st, s)
;
exportSku (Store store) {
// uploading to DBF all Sku for which in (Store, Sku) is specified for the desired warehouse
EXPORT exportSku OBJECTS st = store DBF CHARSET 'CP866';
EXPORT exportSku XML;
EXPORT exportSku OBJECTS st = store CSV ',';
}