Skip to main content

Custom Script

Limited Release
This action is in limited release and is not generally available.

The Custom Script action executes custom JavaScript code within your automation. It is included with Developer Toolkit for users who need custom logic beyond the built-in actions.

Parameters​

JavaScript Code​

Enter your custom JavaScript code. Your script receives a $ object giving you access to all automation data and helper methods.

Editor: Full-featured Monaco code editor with JavaScript syntax highlighting.

Available APIs​

Within your script, the $ object provides access to:

Automation Data​

PropertyDescription
$.emailEmail properties (subject, body, from, to, attachments, etc.) Available in email-processing automations.
$.customCustom variables set by previous actions. Read existing values and write new ones.
$.globalGlobal variables accessible across email rules in the same automation run.

Helper Methods​

// Log a message to the automation history
await $.log('Message to log');

// Log with structured data and a level (info, warning, error)
await $.log('Message', { key: 'value' }, 'info');

Setting Custom Variables​

Set a custom variable by assigning directly to $.custom:

$.custom.myVariable = 'some value';
$.custom.result = { id: 123, name: 'Example' };

Changes to $.custom and $.global are automatically persisted after the script completes.

Autotask API​

If you have an Autotask connection configured, $.autotask provides direct API access:

// Query entities
const tickets = await $.autotask.query('Ticket', 'Status != 5', {});

// Create entities
await $.autotask.create('TicketNote', [{ TicketID: 12345, Title: 'Note', Description: 'Body' }]);

// Update entities
await $.autotask.update('Ticket', [{ id: 12345, Status: 5 }]);

// Get entity field info
const fields = await $.autotask.getFieldInfo('Ticket');

Constraints​

ConstraintLimit
Execution timeout60 seconds
Memory limit512 MB
EnvironmentA secure, isolated JavaScript environment
  • Scripts are syntax-checked before execution
  • Network access is restricted
  • File system access is not available

Example Scripts​

Extract Data​

// Extract a reference number from the email subject
const subject = $.email.subject;
const match = subject.match(/REF-(\d+)/);
if (match) {
$.custom.referenceNumber = match[1];
}

Conditional Logic​

// Set priority based on sender domain
const domain = $.email.from.domain;
const vipDomains = ['important-client.com', 'vip-customer.com'];

if (vipDomains.includes(domain)) {
$.custom.priority = 'high';
} else {
$.custom.priority = 'normal';
}

Data Transformation​

// Combine and format data
$.custom.ticketData = {
title: $.email.subject.substring(0, 100),
description: $.email.body,
requester: $.email.from.address,
received: new Date().toISOString()
};

Logging​

// Log progress for debugging
await $.log('Processing email from: ' + $.email.from.address);
await $.log('Custom data', { result: $.custom.result }, 'info');

Notes​

  • Included with Developer Toolkit
  • Store results by assigning to $.custom properties; changes are automatically saved
  • Errors in your script will cause the action to fail
  • Use the History logs to debug script issues
  • This action does not return variables directly; use $.custom assignments to store results