PSScript Docs / Cookbook

Examples

Complete programs you can drop into a workflow step and adapt. Each one is a full script — every feature it uses is covered in the reference chapters.

Hello world

The smallest useful script — a single log line.

main {
    context$.log("Hello from PSScript.");
}

Full surface tour

Logging with placeholders, nested parameter access, entity creation and persistence, a local map cached at the workflow level, an output value, and connector routing — with a matching rollback.

main {
    // Logging & parameter access
    context$.log("Input parameter A={}", param$["A"]);
    context$.log("Input parameter A.B={}", param$["A"]["B"]);

    // Entity creation & persistence
    var testEntity = PSEntity("com.domain.a.b.c.Test");
    testEntity.identifier("T00001");
    testEntity.val("a", 1);
    testEntity.val("testStr", "T1");
    testEntity.text("name", "en", "John");
    data$.persist(testEntity);

    // Local map + workflow cache
    var tempWorkflowData = {};
    tempWorkflowData["test"]  = "T";
    tempWorkflowData["price"] = 2.45;
    workflow$.cache("name", tempWorkflowData);

    // Output values
    output$["testOut"] = "A1";

    // Routing
    router$.allow("connector1", "connector2");
}

rollback {
    context$.log("Rollback called.");
}

Two entities & routing

Create an order and an audit log, summarise them into the workflow cache, expose the order id, and route to the payment connector.

main {
    // Entity 1 — Order
    var order = PSEntity("com.domain.commerce.Order");
    order.identifier("ORD-2024-001");
    order.val("customerId", param$["customerId"]);
    order.val("total", 149.99);
    order.val("currency", "USD");
    order.text("status", "en", "Pending");
    data$.persist(order);

    // Entity 2 — AuditLog
    var auditLog = PSEntity("com.domain.audit.Log");
    auditLog.identifier("LOG-2024-001");
    auditLog.val("action", "ORDER_CREATED");
    auditLog.val("orderId", "ORD-2024-001");
    auditLog.text("description", "en", "New order created via workflow");
    data$.persist(auditLog);

    var summary = {};
    summary["orderId"] = "ORD-2024-001";
    summary["logId"]   = "LOG-2024-001";
    workflow$.cache("creationSummary", summary);

    output$["orderId"] = "ORD-2024-001";
    context$.log("Order {} created and logged.", "ORD-2024-001");
    router$.allow("payment_connector");
}

rollback {
    context$.log("Order creation rolled back.");
}

Load-or-create with translated text

Idempotent seeding: load a record by identifier, create it only if missing, set localized names and a value, grant access, and persist. Safe to re-run.

main {
    var className = "com.paradicshift.platform.automation.process.Category";
    var baseIconURL = "https://raw.githubusercontent.com/muhsintr/templates/main/media/svg";

    var idn = "PROCESS_CATEGORY_BUSINESS";
    var model = data$.load(idn);
    if (model == null) {
        model = PSEntity(className);
        model.identifier(idn);
    }
    model.text("name", "en", "Business");
    model.val("iconFileName", "%s/money-currency.svg".formatted(baseIconURL));
    model.val("hidden", false);
    model.val("seq", 100);
    model.grantAll();
    data$.persist(model);
}

GIS data generation

A counted loop that creates 50 random geospatial entities inside a bounding box, each with point, polygon and line geometry built with .formatted().

main {
    for (var i = 0; i < 50; i = i + 1) {
        var lon  = util$.randomFloat(28.65, 29.25);
        var lat  = util$.randomFloat(40.88, 41.18);
        var lon2 = lon + 0.010;
        var lat2 = lat + 0.008;

        var e = PSEntity("com.paradicshift.test.GISTempData");
        e.identifier("GIS-TEMP-%s".formatted(util$.uuid()));
        e.text("name", "en", "Istanbul GIS temp entity");
        e.val("city", "Istanbul");
        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));
        data$.persist(e);
    }

    output$["className"] = "com.paradicshift.test.GISTempData";
    output$["message"]   = "50 random Istanbul GIS temp entities created.";
}

rollback {
    context$.log("GIS temp data generation rolled back.");
}

Ask an AI model

Build an input map, ask a configured model a question, and read the answer out of the returned map.

main {
    var input = {};
    input["targetQuantity"] = 50000;
    input["unit"]           = "PCS per day";
    input["product"]        = "pencil";

    var result = ai$.ask(
        "ai_poc_model_identifier",
        "sample-pencil-capacity-session",
        input,
        "How many workers need to produce 50k pencils?"
    );

    context$.log("AI PoC answer: {}", result["answer"]);
}

rollback {
    context$.log("AI PoC ask sample rollback.");
}

Error handling

Catch a runtime error, record a handled status, and run cleanup in finally.

main {
    try {
        context$.log("Starting risky script step.");
        data$.persist({});               // throws: argument is not an entity
        context$.log("This line is skipped when an error is thrown.");
    } catch (err) {
        context$.log("The step failed: {}", err);
        output$["status"] = "handled";
    } finally {
        context$.log("Cleanup always runs.");
    }
}

rollback {
    context$.log("Rollback for try/catch/finally sample.");
}
Keep going Each example draws on the Language reference, System objects and Entities & queries chapters — head back there for the full method tables.