Skip to main content

Language overview

Writing to the log

The first command to know is how to write to the log.

log('Text inserted into package log')
log('Text describing the log data', request)

Log can be used anywhere to write information about the process to the package log. Log is always a text, sometimes followed by data, separated by a ",".

The webhook and Xurrent objects

Working with Xurrent enables Xurrent objects:

  • On an incoming request webhook there is a "request" object.
  • On an incoming task webhook there is a "task" object.
  • On an incoming workflow webhook there is a "workflow" object.

This is the same for other Xurrent webhooks too.

The object contains the data of the Xurrent record that triggered the webhook.

A object can be used directly in any language construct.

log('Id : ', request.id)
log('Impact : ', request.impact)
log('Requester : ', request.requested_by)
log('Requested for : ', request.requested_for)
log('Notes : ', request.notes)
// ...

When working with a Xurrent object, the dot notation is used to access properties, no matter how deeply nested they are. For example:

request.workflow.service.service_owner.manager.primary_email

The possible values can be found in the Xurrent field reference.

Variables

To do calculations, variables are needed to store the results.

let emailTo = request.requested_by.primary_email
log('emailTo', emailTo)

Using intermediate variables helps to keep the code readable.

let manager = request.workflow.manager
log('Workflow manager name', manager.name)

Variables are also used to build Update Data Objects. These are needed for Xurrent updates or mails.

let updateData = {
subject:'New Subject value',
impact:'high',
internal_note:'new internal note'
}

update('requests', request.id, updateData)

The function call performs a update on the request with ID request.id, using the data of $updateData.

The example shows that each property of the Xurrent object that should be updated must be part of the variable object $updateData.

Mathematical expressions

Variables are used to do mathematical expressions. The following operations are allowed:

  • + Addition - can be used on numbers and to concatenate string values
  • - Minus
  • * Multiplication
  • / Division
  • % Modulo operations

Complex expressions can be enclosed in parenthesis.

Conditional execution

if block and else block

Parts that should executed only under certain circumstances are set into a if block.

let emailTo = request.requested_by.primary_email
if (emailTo == 'demouser@techwork.at') {
log('Only executed if emailTo is identical to demouser@techwork.at')
} else {
log('Executed if emailTo is NOT identical to demouser@techwork.at')
}

The else block is optional.

So each expression that calculates to true or false can be placed inside the if brackets.

The following logical expressions are possible:

  • == Values are equal - check for identity
  • != Values are NOT equal - check if different
  • < smaller than
  • > bigger than
  • <= smaller and equal than
  • >= bigger and equal than
  • ! is not - Logical result of a value will be reverted.
  • === Values are equal even in type
  • !== Values are NOT equal - perhaps only in type.

Multiple logical conditions can be concatenated:

  • && Logical AND concatenation - both parts must be true.
  • || Logical OR concatenation - one part must be true.

Logical expressions and variables

It is possible to save the result of a logical expression in a variable

let isOverdue = request.resolution_target_at < new Date()
if (isOverdue) {
log('resolution date is overdue')
}

In the example the actual date is compared with the resolution target date.

Check for existence 1

The "!" operator is used for logical expressions as explained above. It can also be used to check the existence of an webhook object.

Example: Check if a request has no workflow

if (!request.workflow) {
log('There is no workflow')
}

Check for existence 2

A value can be used in a if to check if it exists.

Example: Check if a request has a workflow

if (request.workflow) {
log('There is a workflow')
}

Lists

Some Xurrent objects contains lists of others. E.g request.notes

To get each item of the notes foreach is used:

for (let note of request.notes) {
log('Note : ', note)
}

Each item in the list is identified by the $item variable inside the foreach block.

Additional a specific item can be accessed by index: request.notes[0] is the first element in the list - the first element has the index 0.

Inbound Events

There are three kinds of inbound events:

  • Webhooks
  • Inbound email in a configured IMAP mailbox
  • Timer events of a scheduler

Webhooks are configured in the accounts section.

Inbound email is configured in an e-mail server of your choice. Set the needed parameters in the "E-mail in" section.

Scheduler configuration is similar to cron configuration and explained below.

Scheduler configuration

Scheduler configuration is similar to cron configuration. It consists of six parts that are separated by a space.

* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

Usage Examples:

0 * * * * * -> Every minute, each hour around the clock, each day of the month, seven days a week
0 0 0 * * * -> Every day at 00:00.
0 5 * * * * -> Every hour 5 minutes after the full hour.
*/30 * * * * * -> Every 30 seconds (the second divided by 30)
0 */5 * * * * -> Every 5 Minutes (the minute divided by 5)
0 20,30 1 * * 1-5 -> Monday to Friday at 01:20 and 01:30
0 0 8,12,17 * * 1,3,5 -> To full hour at 08:00, 12:00 and 17:00 on Monday, Wednesday and Friday

Standard variables

Each package execution has a set of standard variables. Some of them depend on the kind of the inbound event.

  • source - depending on the event type. For webhooks it contains:
    • source.body - the request body
    • source.headers - the request headers
  • event / source.event - the event name.
    • For webhooks: request.update, ... ;
    • For scheduled events: scheduler.trigger_name;
    • For inbound email: email-in.trigger_name
  • mail - mail data only available in e-mail in events
  • apiUserId - depending on the configured account.

The source.body value is most important for webhook events. Since this contains the body of the inbound request, its contents depend on the type of webhook.

For Xurrent webhooks, the contents are defined in the Xurrent webhooks documentation. For example, source.body.person_id contains the ID of the person that triggered the webhook, and source.body.payload.sourceID contains the source ID of the Xurrent record that triggered the webhook.