Skip to content

Scripting

Emakin incorporates a scripting environment that enables the creation of custom scripts to automate tasks, extend system functionalities, and facilitate integrations with external systems.

Scripting Environment

The scripting environment is predicated on the JavaScript programming language. JavaScript is a widely adopted language, and within Emakin, it is isolated from the underlying operating system to ensure a secure and stable execution environment.

The script execution runtime may vary depending on the script type, with scripts executing in either a server-side environment or a client-side browser environment. Further details on the specific runtime environment are provided in the documentation for each script type.

Scripting Reference

Environment

$ActiveUser
Active user as Identity

$Culture
Current culture information (e.g. en-US, tr-TR)

$Initiator
Initiator user as Identity

$Priority
Current priority (0-5) information

$TestMode
True when process in test mode

$Domain
Current domain information

Data Access

$Xml
Process data manipulation

$Database
Relational database access

$Documents
Document management

$Files
File archive

$ActivityStream
Object activity stream

$XmlRepository
No-SQL xml database

Organization Data

$Membership
Organization data like users, groups.

$Delegation
Delegations between users

Processes

$Case
Current case instance

$WorkItem
Current work item instance

$Instance
Current workflow instance

Date and Time

DateTimeOffset
Timezone aware date and time

$Calendar
Rule based date time operations

Integration

$Messages
e-Mail sending and mime message parser

$Rest
Rest API client

$Services
SOAP API client

Utilities

$Templates
Template renderer

$Decisions
Business rule engine

$Cache
Distributed cache database access

Helpers

XmlWriter
Xml document writer

$Crypto
Hashing, encryption and digital signatures

Script Example

The following script provides an illustration of finding and replacing text within a Word document:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
var fileId = $Xml.Evaluate('Contract/ContentFileId');
var writer = new Writer();

writer.LoadFromBase64($Files.GetBase64(fileId));

$Xml.SelectAll('Contract/Fields/Field', function (field) {

    var name = field.Evaluate('Name');
    var value = field.Evaluate('Value');

    // find %NAME% and replace with field value
    writer.Content.Replace('%' + name + '%', value);
});

$Files.SetBase64(fileId, writer.SaveToBase64(".docx"));