Script Collection for Straatos
This articles describes the Script Collection for Straatos
This page contains some samples and help for Scripts that can be used in Straatos.
Adjust Height of Table in Web Validation
It is useful to adjust the default height of the table in Web Validation (see red box area):

You can do this by copying the following script into the 'Prescript' section of the workflow.
If you use multiple Web Validation steps in a single process and want to display the table with different heights in different steps, you can use an if statement to do that.
Line Items from Database
This script allows you to retrieve and display line items from a database based on a specific Index Field value.
Example use case:
When a PO Number is entered in an index field, the corresponding line items for that PO Number can be fetched from the database and displayed in Web Validation.
Configuration steps
Identify the Index Field that should trigger the line item retrieval.
Example: PONumber.
Navigate to the 'Change Script' section of the selected Index Field.
Implement the script to fetch and populate line items dynamically.
Set the following options to on:
Change Script Changes Field Definition.
Change Script Changes Field Values.
Change Script is Asynchronous.
In the 'Change Script', use the following code below.
Onwards (Move Documents to Next Step)
Onwards is a boolean value that controls whether a workflow instance/document moves to the next activity after the script execution.
Default behavior:
Default value:
true.
If true, the document automatically proceeds to the next step in the workflow.
Example use case
Set onwards = false to keep a document in the current workflow step (e.g., if an error occurs and requires manual intervention).
Sequence Numbering
This function generates an incrementing number for a specified identifier.
Key features:
The identifier can be reused across multiple processes.
The generated number is unique for each identifier.
It is the user's responsibility to ensure that is globally unique to prevent conflicts.
Show/Hide Fields
This script applies to Web Validation Scripting.
In Web Validation, fields can be shown or hidden dynamically based on index field values.
Example use case:
If a user selects 'Invoice' as the document type, specific Index Fields related to invoices should be displayed.
If a user selects 'Correspondence', a different set of fields should be visible.
Implementation steps
Define the show/hide logic in the Workflow-Level Script Library.
This ensures reusability across multiple scripts.
Call the function in relevant script sections to dynamically adjust visibility based on user input.
Best practice
Store the function in the Script Library for centralized management and easier maintenance.
Enter the following code below.
The above code inserts two functions. One to hide/unhide fields for Document type and the second function hides/unhides the fields for the Document type Correspondence. Both functions accept two parameters, firstly the fields, which is a collection of all index fields for the workflow, and secondly 'hide' which is a boolean true/false.
On the workflow level, go to the 'Change Script' section and set the following options to 'ON':
Change Script Changes Field Definition.
Change Script Changes Field Values.
With those options set to 'on', we system knows that the UI will be updated by the script. In the 'Change Script' enter the following code:
The code will call the functions defined before and passes all the fields. Furthermore, depending on what the value is in the DocumentType field, the boolean 'hide' is set to true or false.
Timer
Straatos supports a timer event. The timer event (officially the 'Timer Boundary Event') allows a task or document to be delayed at a predefined time.
Example use case:
Send an Invoice only on the invoice Date. Delay an error retry by 5 Minutes.

The timer event can be setup based on three generic options.

Duration (in days, hours, minutes). This delays a task for a certain number of time from the time the task reaches this step.
Time Cycle based on a Cron Expressen: Supporting a delay to be sent on a specific time/date. For example every 1st of the Month, Every 10 Minutes etc.).
Workflow/Index field:
Based on a date/time of an index field.
Details on Index field date.
The value can be set in the following way:
2016-12-06T09:00:00+01:00
The Time is optional. For example the following is valid:
2016-12-06.
In this case, the documents waiting in the timer event are released at midnight on the 6 December 2016. Midnight refers to UTC/GMT.
2016-12-06T09:00:00:
In this case, the time is set to 09:00 am UTC/GMT time.
2016-12-06T09:00:00+01:00:
In this case, the time is set to 09:00 UTC/GMT +1 (timezone).
Script to use to set a date:
Hide Table Columns in Web Validation
If you have created a table and want to display/hide certain columns depending on the workflow step, here is how it is done:
Example: User Task (Accounting Coding) will see the following table column fields:
KontoListe.
KostenstelleListe.
Betrag
User Task (PO Exception) will see the following table column fields:
ArtikelNr.
Bezeichnung.
Menge.
ME.
Preis.
BetragCHF.
Script Library
Table column field start from 1
Pre Script:
Enable/Disable Mandatory Option for Fields in Web Validation
Here is a script which enables/disables the field mandatory property. Below is the script 'mandatory' shall be call from function as 'true'.
Blank Page Removal
The following script removes blank pages from a document.
Before executing the script:
Enable the 'Create Separate Pages from PDF' option in the Start Event settings.
Use the script below to detect and remove blank pages automatically.
Implementation
The script scans each page to determine if it is blank and removes it accordingly.
This ensures that only relevant content remains in the document.
Error Handling with Error Event
The error event is able to catch the error in a module and to route a task/document to a different flow in the process. The diagram below is a simple flow that catches an error event and routes it to a different step.

The step 'Script simulate error' produces an error. The Error Event catches the error and routes the document to the step 'Read error message'.
The script error event is triggered by most modules automatically. When using a script task, then an error can be triggered using the following script.
In order to display the original error message (or to use the original error message in script) in the step 'Read error message', use the following code to retrieve the message.
The variable 'ErrorMessage' above is a Workflow Index field.
Start New Workflow from Script
Ajax Call with XML Data and Ampersand (&)
When sending data via an AJAX call with content type application/x-www-form-urlencoded, special characters like ampersand (&) require special handling.
Scenario:
If your data includes an ampersand, such as:
In normal XML conversion, & is automatically converted to &:
When using application/x-www-form-urlencoded, the ampersand (&) in & is still problematic because & is used as a parameter separator in URL-encoded data.
To resolve this, encode & as %26, so your XML becomes:
With this, you are then able to send the data.
Sample code is below
The var xOutput would be your XML body. The important line are the encodedData where all & are replaced by '%26amp;' then the form data is assigned. In the formData.append, you can add all the fields that need to be sent. At the end is the encodedData which contains modified XML.
Table Updates in Script Task
In Straatos, table fields can be updated dynamically using scripts. The following example demonstrates how to:
Access a table.
Retrieve line items and fields.
Perform calculations and assign values.
Example: Summing the LineTotal Field.
The script below:
Checks if there are any line items.
Iterates through each line item and retrieves the value of the LineTotal field.
Sums up all LineTotal values in the invlinesum variable.
Assigns the sum to the index field NetTotal.
Logs the result in the console.
When users edit and delete line items in a MyHome task, the line numbering may become inconsistent. This script ensures that the LineNumber field remains sequential by renumbering all line items after changes.
How the Script Works:
Iterates through all line items in the table.
Checks if the Match field exists (i.e., not null or undefined).
Assigns a continuous number to the LineNumber field.
For the first column 'LineNumber' it assigns the value of the counter.
At the end (starting with _table ={) the values are assigned to the table.
Table Updates in MyHome
The following function can be defined in the Script Library and used in My Home to update the table lines.
The script goes through each line item and sums up the LineTotal into the variable invlinesum. The invlinesum, after all amounts of the table are added is populated into the header field 'NetTotal'. This script can be executed when the table is updated to show the sum of an amount in a table.
The script below updates the line item values in My Home based on a lookup. In the Ajax call, a web service is called to return the Supplier data.
Based on the returned values, 4 table line items are updated.
Split Document
Get File Size
When you need to get the file size of a document received, you can do this with the following script below.
Last updated