Skip to content

JavaScript Action

The JavaScript action lets you run custom JavaScript code inside a job. You have access to built-in functions for working with data, artifacts, HTTP requests, and other jobs — all prefixed with _.

When to use this

  • You need custom logic that doesn't fit a standard action type
  • You want to process or reshape data between other actions
  • You need conditional logic or loops in your workflow
  • You want to combine multiple operations in a single action

How it works

Your JavaScript code runs in a sandboxed environment with access to the previous action's output and a set of built-in helper functions. All built-in functions are prefixed with _ (underscore).

Built-in functions

Input and output

FunctionDescription
_GetInput()Returns the output from the previous action
_GetInput(position)Returns the output from a specific action by position number

Job parameters and variables

FunctionDescription
_GetParameter(parameterName)Read a job parameter value
_SetParameter(jobGuid, parameterName, value)Update a job parameter
_GetVariable(variableName)Read a job run variable
_SetVariable(variableName, value)Set or update a job run variable

Running other jobs

FunctionDescription
_RunJob(jobGuid, input, inputFiles, variables, verbose, waitForCompletion, name)Trigger another job. Set waitForCompletion to true to wait for it to finish before continuing.
_ClearJobCache(jobGuid)Clear the cache for a specific job

HTTP requests

FunctionDescription
_MakeHttpRequest(url, token, method, headers, body, contentType, numberOfRetries, responseErrorText)Send an HTTP request to an external service

Data conversion

FunctionDescription
_ConvertToString(obj, sourceFormat)Convert an object to string
_ConvertToJson(input, sourceFormat, ...)Convert from various formats to JSON
_ConvertToXml(input, sourceFormat, rootName, ...)Convert data to XML
_ConvertFromExcel(artifactName, targetFormat)Convert an Excel artifact to another format

String operations

FunctionDescription
_EncodeHtml(term)HTML-encode a string
_DecodeHtml(term)HTML-decode a string
_EncodeUrl(term)URL-encode a string
_DecodeUrl(term)URL-decode a string
_EncodeToBase64String(str)Base64-encode a string
_DecodeFromBase64String(str)Base64-decode a string
_GetStringHash(value)Get the SHA256 hash of a string
_ClearTextFormatting(text)Strip HTML tags from text

Date and time

FunctionDescription
_ConvertToDate(date)Parse a string to a date
_ConvertDateToTicks(date)Convert a date to ticks
_ConvertDateFormat(date, format)Format a date with a custom pattern
_ConvertTimeFromUtc(date, timezoneId)Convert from UTC to a specific timezone
_ConvertTimeToUtc(date, timezoneId)Convert from a timezone to UTC
_AddToDate(date, days, hours, minutes, seconds)Add time to a date
_CompareDates(date1, date2)Compare two dates
_GetFirstDateOfWeek(date)Get Monday of the given date's week
_GetLastDateOfWeek(date)Get Sunday of the given date's week
_GetFirstDateOfMonth(date)Get the first day of the month
_GetLastDateOfMonth(date)Get the last day of the month
_GetDatePart(date, datePart)Extract a part: year, month, day, dayofweek, week, hour, minute, second
_GetDateDiff(startDate, endDate, diffType)Get the difference in days, hours, minutes, seconds, or ticks

Artifacts

FunctionDescription
_GetArtifact(artifactName)Get artifact metadata
_GetArtifactContent(artifactName)Get the content of an artifact
_SaveArtifact(artifactName, content, contentType)Save content as an artifact
_DeleteArtifact(artifactName)Delete an artifact
_UploadArtifact(url, token, artifactName, useMultipart)Upload an artifact to an external URL
_DownloadArtifact(url, token, artifactName)Download a file and save as artifact
_ExtractArtifact(artifactName, password)Extract a ZIP or encrypted archive

PDF and QR codes

FunctionDescription
_GeneratePdf(html, artifactName)Generate a PDF from HTML content
_ExtractPdfPages(extractType, artifactName, searchTerm, ...)Extract content from a PDF
_GenerateQrCode(content, pixelsPerModule, drawQuietZones, artifactName)Generate a QR code image

Cryptography

FunctionDescription
_Encrypt(salt, str, encryption)Encrypt a string using HMACSHA256, SHA512, or SHA256
_GetClientAssertion(pem, aud, iss, sub, scope)Generate a JWT client assertion
_MathModulus(a, b)Modulo operation

Logging and control flow

FunctionDescription
_Log(logMessage)Log a message (only visible in verbose mode)
_RaiseError(errorMessage)Stop the job with an error

Example

Fetch data from an API, parse it, save it as an artifact, and log the result:

var data = _MakeHttpRequest("https://api.example.com/items", "Bearer token123", "GET", null, null, null, 3, null);
var parsed = JSON.parse(data);
_SaveArtifact("items.json", JSON.stringify(parsed), "application/json");
_Log("Saved " + parsed.length + " items");

Tips

TIP

Use _GetVariable and _SetVariable to pass data between actions within the same job run. Variables persist for the duration of the run.

TIP

Use _Log to add debug output during development. Log messages only appear when the job is run in verbose mode.

TIP

Line breaks in your JavaScript code can use <lf> as a placeholder — it gets replaced with an actual line break at runtime.

Common mistakes

WARNING

All built-in functions are prefixed with _. Calling GetInput() without the underscore will fail — use _GetInput().

WARNING

_MakeHttpRequest will not throw an error on non-200 responses by default. Check the response content to handle API errors in your logic.