Skip to content

Automations

The Automations module enables users to extend the system with custom workflows. It allows running custom business logic, integrating with external systems, and scheduling automated tasks to improve efficiency and reduce manual work.

Use Cases:

  • Run AI-powered data analysis and generate insights.
  • Send automated email notifications based on specific triggers.
  • Generate and export reports on a scheduled basis.
  • Prepare PDF documents and attach them to the system.
  • Integrate with third-party services for data synchronization.
  • Perform data cleanup and maintenance tasks automatically.
  • Run custom scripts to process data and update records in the system.

Examples:

  • Pull exchange rates from an external API and update the system.
  • Retrieve emails from an external mail server.
  • Optimize video files within the system.
  • Validate VAT numbers using the VIES service, generate a PDF confirmation, and attach to the system.

Prerequisites

  • Python installed in c:\Python
  • Python libs pip install requests pyodbc uuid logging

Configuration

  • system:automation_appname - name of the app authorized to run automations default erp
  • system:automation_python - location of python default c:\\Python\\python.exe

Basics

  • Automations are stored in the /automations directory of the application.
  • Automation names must follow the format: A001-YourAutomationName.
  • Only a single app instance is authorized to run automations.

Environment Variables

  • Automation scripts read environment variables starting with JETQUERY_.

Warning : environment variables are visible in a scope of the user running the automation process for example IIS/Kestrel. For localsystem you should set them in system environment variables.

Batchfile
setx /M JETQUERY_TOKEN_app.platformaerp.com "12345-secret-value"
iisreset    # reset required

Predefined:

  • JETQUERY_TOKEN – Represents the API token for authentication, reads from Environment variables JETQUERY_TOKEN_+ JETQUERY_HOST (e.g., JETQUERY_TOKEN_app.platformaerp.com) token must match host/tenant other tokens are ignored
  • JETQUERY_HOST – Represents the host URL or tenant ID. example app.platformaerp.com !WARNING! without scheme https:// or http://
  • JETQUERY_DSN – Represents the database connection string.
    • If not provided, it is generated automatically, e.g.: SERVER=192.1.1.1;DATABASE=ERP;UID=platforma;PWD=password;Trusted_Connection=no;
    • The driver must be added in the script, for example:
      DRIVER={SQL Server};
  • (future) JETQUERY_FILES – Path to the local tenant files.
  • (future) JETQUERY_ARCHIVE – Path to the local tenant temporary archive, which is cleaned automatically according to the data retention policy.

Configuration automations\automation.json

JSON
[
  {
    "name": "A001-run-kursy",
    "type": "python",
    "description": "Automatyzacja pobierania kursów walut NBP",
    "acl": "erp_administrator",
    "cron": "* * * * *"
  },
  {
    "name": "A002-tools-minimal",
    "type": "win-x64",
    "description": "Testowy skrypt nie wykonuje czynności zwraca komunikat error,success i random exit code 0-1",
    "acl": "erp_administrator",
    "cron": "* * * * *"
  }
]

API

Text Only
1
2
3
4
5
/api/core/automations/del/{{automationName}}            
/api/core/automations/run/{{automationName}}?cron={{cron}}
/api/core/automations/run/{{automationName}} 
/api/core/automations/status/{{jobId}}               
/api/core/automations/browse                

Testing in local environment

SETUP ENVIRONMENT VARIABLES

Run cmd as administrator

Batchfile
1
2
3
4
5
6
7
echo %JETQUERY_TOKEN%
echo %JETQUERY_HOST%

setx JETQUERY_TOKEN "MyValue"
setx JETQUERY_HOST "https://app.platformaerp.com"
:: połączenie z bazą danych
setx JETQUERY_DSN "your_dsn_value" 

Basic dotnet template

C#
namespace tools_minimal
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //get a random exit code 0,1
            int random = new Random().Next(0, 2);


            //Write to stdout
            Console.WriteLine($"This is a test. Random Exit code:{random}");
            //Write to stderr
            Console.Error.WriteLine("This is an error.");

            //read anvironment variable
            var envVar = Environment.GetEnvironmentVariable("JETQUERY_HOST");
            Console.WriteLine($"JETQUERY_HOST: {envVar}");

            Environment.Exit(random);
        }
    }
}

Build script examples:

Batchfile
1
2
3
4
5
# AOT require c++
dotnet publish -c Release -r win-x64 -p:PublishAot=true

## without AOT
dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true --self-contained true

(deprecated) Appendix Schedule in Windows Task Scheduler

Previous deprecated version was based on Windows Task Scheduler and was removed. Still can be used in legacy systems directly from Server command line.

Some examples, run cmd as administrator, scripts:

Batchfile
:: Run API to pull mails
schtasks /create /tn "platformaerp run-api mail-pull" /tr "python.exe C:\Automations\run-api.py --url /api/core/mail/pull" /sc minute /mo 30 /RL HIGHEST

:: RUN API Dla faktur sprzedazowych 
schtasks /create /tn "platformaerp run-vies sprzedaz" /tr "python.exe C:\Automations\run-vies.py --componentname=saleinvoice" /sc minute /mo 60 /RL HIGHEST

:: RUN API Dla faktur zakupowych 
schtasks /create /tn "platformaerp run-vies zakup" /tr "python.exe C:\Automations\run-vies.py --componentname=orderinvoice" /sc minute /mo 60 /RL HIGHEST

:: RUN RENDER MAIL
schtasks /create /tn "platformaerp run-mail-render" /tr "python.exe C:\Automations\run-mail-render.py --componentname=orderinvoice" /sc minute /mo 30 /RL HIGHEST

:: RUN API Dla kursow walut 
schtasks /create /tn "platformaerp run-kursy" /tr "python.exe C:\Automations\run-kursy.py" /sc minute /mo 120 /RL HIGHEST