Skip to main content

Reserved Power Script variables

Power Scripts are an advanced type of Flow Step, written in JavaScript, that give complete control over a Query's data. This article covers the reserved variables available in Power Scripts that make it easier to shape data. It assumes a basic familiarity with Power Scripts.

$omit()

Calling $omit() excludes the row from the final result set. See the lodash section below for an example.

$record

An object containing every value in the row, referenced by Field alias. For example, in a Query with three columns whose aliases are aliasOne, aliasTwo, and aliasThree, with first-row values valueOne, valueTwo, and valueThree, the $record object for the first row looks like this:

A Power Script editor showing the $record object structure
The $record structure.

Change a column's value, or add a new column, like this:

A Power Script assigning a $record value and adding a new column
Modifying and adding columns on $record.

$local

An object that persists across rows. In this example we replicate the Percent of Total Flow Step using Power Scripts and the Flush Flow Step. The setup looks like this:

A Flow Steps panel with two Power Scripts and a Flush between them
The $local setup.

The first script totals the freight value across every row:

A Power Script accumulating a running total into $local
Computing the total.

Then the Flush Flow Step ensures this script has been applied to every record before the percent-of-total calculation runs:

A Power Script dividing each record's freight by the $local running total
Calculating the percent of total.

$fields, $query, $datasource

These variables contain information about the underlying properties used to generate the Query:

  • $fields is an object with information like dataType, position, label, and name.
  • $query contains params, dataTypes, fields, options, language, user, and result.
  • $datasource contains defaultLinkType, family, languages, naturalId, id, ownerId, name, description, type, scannedAt, schemaUpdatedAt, schemas, source, sourceId, settings, createdAt, updatedAt, fileId, and features.

Lodash (_)

Lodash is a JavaScript library for manipulating collections (arrays, objects, strings). For example, to exclude rows where a column contains a negative number:

A Power Script using lodash some() to omit rows with a negative number
Using lodash to omit rows.

The function above uses the lodash some() method. some() takes a collection as the first argument and a function as the second, iterating through every value and running the function on each until one returns true or there are no more values. For example, for the row below:

1-22345

_.some() evaluates the function with 1 first (a number greater than zero, so false), then -22 (less than zero, so true). It stops and returns true, so the if (doNotKeep) check is true and calls $omit(), removing the row. See the lodash documentation for more.

Moment.js (moment)

Moment.js makes creating and manipulating JavaScript dates easy. For example, suppose a Query returns opportunities that are only valid for 30 days. To identify expired opportunities, you would normally group by status, sort by open date, then check whether the value plus 30 days is after the current date. Instead, a quick Power Script can calculate whether a value passed an expiration date and add a new column with the result:

A Power Script using moment to compute an expiration date and an isExpired flag
Using moment to flag expired records.

This script creates a date from the openDate value, adds 30 days, stores it in a new expirationDate Field, and adds an isExpired Field that is true when the expiration date is before now and the status is open. See the moment documentation for more.

Also available through the REST API
Everything on this page is built on Informer's public REST API, the same one the product uses, so your scripts and integrations can do it too. Developer reference: Queries.