Skip to main content

Code Appendix

Worked code snippets for the places in Informer where you can write a little JavaScript: Calculated Fields, Power Script Flow Steps, and Web Query response parsers. Use them as starting points and adapt the Field aliases to your data.

Where code runs in Informer​

ContextWhat you writeKey variables
Calculated FieldsA JavaScript expression that produces a Field's value, one row at a time. The value of its last line becomes the Field's value.$record['alias'] for the current row's Fields (read only); moment() for dates; _ for lodash.
Power Script Flow StepsJavaScript that runs once per record as part of a Query's flow, and can change the record in place.$record for the current row; $local to carry values across rows.
Web Query response parsersJavaScript that turns a web service's response into records.response for the payload; push() to emit rows; next() to send another request.

The script sandbox exposes a consistent set of globals, including $record (the current row), $local (a place to keep state across rows), $field/$inputs, and saved functions, so the same patterns carry from one context to the next. See Reserved Power Script variables for the full list.

A quick example​

Formatting a date Field with Moment.js in a Calculated Field:

var date = $record['fieldAliasGoesHere'];
var formattedDate = moment(date).format('MM-DD-YYYY');
formattedDate;

In this section​

ChapterWhat's in it
JavaScript Examples - StringsTake parts of a string, add or strip characters, pad, and split.
JavaScript Examples - DatesCompare, format, add to or subtract from, and take apart dates.
JavaScript Examples - ArraysAppend, remove, sort, and join, plus splitting and pivoting multi-valued Fields into columns.
Power Script ExamplesGrand totals and per-group totals with $local and Flush, and comparing two dates.
Web Query Custom Response ParsersFollow-up requests with next(), pagination, token retrieval, and unioning Datasets through the REST API.

Where do I look when...​

You want to...Start here
Show only part of a text valueHow to display parts of a string
Format a phone number, or pad an ID with leading zerosHow to manipulate a string
Show a date as text in a set patternHow to format a date
Calculate a due date or an expiration dateHow to add or subtract from a date
Flag records where two dates differHow to compare two dates in a Power Script
Spread a multi-valued Field across columnsHow to split a multi-valued field into separate columns
Add a grand total, or a total per group, to every rowHow to calculate a sum total aggregate via a Power Script, then How to aggregate values on specific groups of data
Load every page from an API that pages its resultsHandling Pagination in Web Queries
Call an API that needs a short-lived access tokenAutomating Token Retrieval in Web Queries
Combine several Datasets into oneUnioning Two Informer Datasets Using a Web Query and the Informer REST API