PSScript Docs / Reference

Entities & queries

Entities are PSScript's first-class data records. PSEntity builds and mutates them; PSEntityQuery reads them back with a fluent, chainable builder.

Creating entities

Construct an entity from its fully-qualified class name. The entity starts empty; you populate it with the methods below and then persist it.

var order = PSEntity("com.domain.commerce.Order");
order.identifier("ORD-2024-001");
PSEntity(typeName)

Create a new, unsaved entity of the given class.

entity.identifier(idn)

Set a stable business identifier — the key you later pass to data$.load.

Load-or-create A very common pattern loads an entity by identifier and constructs a fresh one only when it does not yet exist, so a script is safe to re-run:
var idn = "PROCESS_CATEGORY_BUSINESS";
var model = data$.load(idn);
if (model == null) {
    model = PSEntity("com.paradicshift.platform.automation.process.Category");
    model.identifier(idn);
}
model.text("name", "en", "Business");
data$.persist(model);

Fields & values

entity.val(field, value)

Set a scalar field (string, number, bool, …). value is an alias of val.

entity.val(field)

Read a field back; returns null if unset.

order.val("total", 149.99);
order.val("currency", "USD");
order.val("hidden", false);

context$.log("total = {}", order.val("total"));   // 149.99

Multilingual text

Text fields are stored per locale, so a record can carry its name or description in many languages at once.

entity.text(field, locale, text)

Set the localized text of a field. The field name and locale are auto-detected by order, so ("name", "en", …) and ("en", "name", …) both work.

entity.text(field, locale)

Read a localized value back. Reading a locale that was never set is a runtime error, so guard or set it first.

component.text("name", "en", "Execute access");
component.text("name", "fa", "دسترسی اجرا");

GIS geometry

Entities can hold geospatial fields expressed as WKT strings. The geometry is parsed and validated when you set it.

entity.gis(field, wkt)

Attach a geometry to a field from a WKT string. gisWkt is an alias.

Supported WKT geometry types include points, lines, polygons and their multi-variants:

e.gis("location", "POINT(%f %f)".formatted(lon, lat));
e.gis("area_1",   "POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))"
                  .formatted(lon, lat, lon2, lat, lon2, lat2, lon, lat2, lon, lat));
e.gis("path",     "LINESTRING(%f %f, %f %f, %f %f)"
                  .formatted(lon, lat, lon2, lat2, lon3, lat3));

Access control

entity.grantAll()

Grant open access to the entity — useful for shared platform data such as categories and model properties.

entity.openAccess(accessType)

Open a specific kind of access (for example "list") without granting everything.

Persisting & linking

Saving, deleting and relating entities is done through data$ (see System objects). An entity also exposes a convenience delete.

data$.persist(entity)  ·  data$.link(child, parent, relation)  ·  entity.delete()
data$.persist(subCat);
data$.link(subCat, model, "IN_PARENT_CATEGORY");

PSEntityQuery

Build a read query against a base class, chaining select clauses (what to return), filter clauses (which rows) and traversal clauses (follow relations). Pass the finished query to data$.query().

var q = PSEntityQuery("com.domain.commerce.Order")
            .selectId()
            .selectVal("total")
            .filterVal("currency", "equals", "USD")
            .filterVal("total", "greater_than", 100);

var rows = data$.query(q);

Select clauses

.selectId()include the internal id
.selectIdentifier()include the business identifier
.selectVal(field)include a scalar field
.selectText(field, locale)include localized text
.selectCount(field)aggregate count
.selectSumVal(field, alias)aggregate sum of a field

Filter clauses

.filterId(value)match on internal id
.filterIdentifier(value, op)match on business identifier
.filterVal(field, op, value)match on a scalar field
.filterText(field, locale, op, value)match on localized text
.filter(name, op, value)generic: routes to id / identifier / val automatically
.filterGIS(field, predicate, wkt)spatial match against a WKT geometry (filterGis alias)

Traversal

.forward(relation)follow a relation in its forward direction
.backward(relation)follow a relation in reverse

Filter operators

The comparison operator in a filter is given as a string:

Operator stringMeaning
"equals"equal to
"not_equals"not equal to
"greater_than"greater than
"greater_than_or_equals"greater than or equal
"less_than"less than
"less_than_or_equals"less than or equal
Filter values A filter value must be a scalar (string, number, bool, null) or a map — entities, queries and system objects cannot be used as filter values.