Articles in this section

Debug your scripts in integrator.io

To add JavaScript debugging statements to your integrator.io scripts, call a console object method, as follows:

Method

Description

Level

console.debug(string1, string 2, ...)

Fine-grained informational events that are most useful to debug an application.

Debug

console.info(string1, string 2, ...)

Equivalent methods for printing informational messages to the execution log.

Info

console.log(string1, string 2, ...)

console.warn(string1, string 2, ...)

Output shown in potentially harmful situations.

Warn

console.error(string1, string 2, ...)

Log error events that might still allow the application to continue running.

Error

Integration runtime debugging is available for export and import hooks as well as transformation and filter scripts.

Each method will write to the script’s execution log, as follows:

  • Debug – statements written only when the debug level is applied

  • Info – always written

  • Warn – always written

  • Error – always written

For example, you might want to send verbose messages to the log file if a field is not found in the exported records during a preSavePage hook:

function preSavePage (options) {
  options.data.forEach(d => {
    if (!d.shipmethod) {
      // Build error message and pass order by concatenating 
      // string variable in %s - string placeholder
      console.error('Missing shipping method for order#: %s', d.order)
    }
  })
  return {
    data: options.data,
    errors: options.errors,
    abort: false
  }
}

If you start debugging and that condition occurs in the script, the output in the execution log might appear as follows:

360086189772-debug-2.png

Important

Statements are written to the execution log until an error is encountered – an actual JavaScript error, if any, as opposed to a console.error() call. The script error is recorded on the flow Run dashboard and not in the execution log.

Execution logs

The execution log displays historical events and debugging output for the selected script for up to 30 days or however long your data retention plan allows . You can also apply a filter (the default is Last 15 minutes) to narrow the time frame of logs shown.

You can also filter the execution logs according to flow Step (such as an export or a lookup), Function type, and Log level.

Start debug level

A debug statement – printed by console.debug() – is considered the highest logging level, typically with the most verbose output. The debug level is always disabled until you initiate the script debugger for a specific time frame.

You can start debugging in either of two places in integrator.io, depending on your requirements:

  • In Flow Builder – If your flow contains a hook and it is scheduled or started by an export or download (that is, not by listening to a webhook in a “real-time flow”), then you will see a Scripts tab in Flow Builder.

  • On the Scripts page – Since a script is a shared resource, which may be used in one or more flow steps, flows, or integrations, you can access any script at Resources > Scripts, when Developer mode is turned on.

In the Scripts tab or page, click the Actions overflow (...) menu, and select View execution log.

To turn on the debugger, click Start debug, choose how long you want it to run, and then select Apply.

360086272591-debug-3.png

When you’re ready to debug the script, click Run now if you’re already working in Flow Builder. Of course, if your script is invoked within a flow, that flow should run jobs within the debugging time frame, whether as a result of a scheduled start or a webhook caller sending a request.

Continuing with the example above, let’s add a debug statement that returns the entire exported data object only when the debug level is set:

function preSavePage (options) {
  console.debug('Data before preSavePage hook', JSON.stringify(options.data))
  options.data.forEach(d => {
    if (!d.shipmethod) {
      console.error('Missing shipping method for order#: %s', d.order)
    }
  })
  return {
    data: options.data,
    errors: options.errors,
    abort: false
  }
}

Then, after applying the debug log level, the data object is displayed in the execution log:

360086326592-debug-4.png
Was this article helpful?
2 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.