Custom Decisions

Add custom decision steps to your Campaigns & Programs

In This Guide

  • Intro to Custom Decisions
  • API Reference
  • Step by Step Examples

Custom Decisions Intro

Custom Decisions let you easily make custom Eloqua decision steps.

The logic behind these decisions is completely custom. Here are some examples:

  • Simple decisions e.g. split-testing
  • External API e.g. whether they attended a webinar
  • Internal API e.g. whether they purchased via. your accounts API

Creating a Custom Decision is incredibly simple: place the Custom Decision on your Campaign/Program. Click it. A code editor opens. Change a few lines of JavaScript. Then click 'test' to check it works.

It really is that simple. And if you prefer not to do the JavaScript, help is available.

Intro Video

play_circle_outline Play 40 second demo

API Reference


You can use eloqua.log("Message here...") anywhere in your code.

eloqua.log("Hello World!");

This built-in function logs whatever you pass to it. This message will be visible in 2 places:

  1. When you test your feature, it will display in a blue info box
  2. In the 'Logs' tab after your feature runs in a campaign or program


Every Custom Decision starts with eloqua.each(...).

eloqua.each(contact => {
    // Your code here

This function will loop over all the contacts sent by Eloqua.

The contact object properties & functions listed below are available inside this wrapper. The contact object inside this loop will refer to each contact, one at a time.


The contact.done function sends an outcome (true or false) back to Eloqua.

eloqua.each(contact => {
    contact.done(true); // sends the contact down the 'yes' decision path
Send contact.done(true) to return a 'yes' decision-outcome, and contact.done(false) to return a 'no' outcome.


The contact.fields object lets you access the contact's fields from the Eloqua database:

eloqua.each(contact => {
    var name = contact.fields.C_FirstName + ' ' + contact.fields.C_LastName;
    eloqua.log(name); // logs contact's full name

Fields must be accessed using their internal field-name.

The editor's autocomplete makes this extremely easy. Just start typing and all the fields in the database (including custom fields) will be available & type-checked.


The contact.error function elegantly handles errors:

eloqua.each(contact => {
    contact.error("My custom error message");

Specifically, it does 2 things:

  1. It lets Eloqua know your function has errored (for that contact). If you chose a 'route errors' step in your campaign/program, the contact will be sent there.
  2. The error message will be elegantly displayed when you test your function, or in the Log tab.


Basic Example - Split Testing

This basic example just creates a random 50:50 split. This can be used for split-testing.

eloqua.each(contact => {
    let rand = Math.round(Math.random());
    if(rand === 0){ contact.done(false); } else { contact.done(true); }

API Example

The below example demonstrates using a Custom Decision powered by an external API.

Specifically - this uses a tool called 'Yes or No' to randomly make the decision for us.

const fetchJSON = require('node-fetch-json'); // use node-fetch instead if you do not want JSON
eloqua.each(contact => {
        .then(data => {
            if(data.answer === 'yes'){ contact.done(true); } else { contact.done(false); }
        .catch(err => { contact.error(err) })

Note that the important part is still that we return either contact.done(true) or contact.done(false) for each contact, which sends the result back to Eloqua as yes or no decision outcomes.

Advanced Topics

Advanced Use-Cases Only

This section covers advanced topics. Most people will never need to use these settings. If you do have an advanced use-case, we recommend our consulting services!

Config Object

In the 'Action' tab if you click on the more icon ('...'), you can select Advanced Settings.

One of these settings is a config object. This is designed for a situation where you want to re-use the same code, but pass different "settings" into it each time.

The entire config object is available as eloqua.config - therefore you can access whatever properties you give it:

eloqua.config.my_setting_name // accesses the config object supplied

Again - the config is unique to each instance of your app, and is designed to allow re-use.

Global Settings Object

You may want to have some values stored outside of your code. E.g. API keys. This can be useful for security (less visible), and also means they can be centrally maintained even if they are used in many functions.

You can set global config through the Just Add Features global settings.

An object with all the global settings is available as eloqua.globals - therefore you can access whatever global properties you setup:

eloqua.globals.my_global_setting // accesses the globals object