Skip to main content
All CollectionsTriggersAdvanced trigger control
Send a particular stage of a Trigger Program only once
Send a particular stage of a Trigger Program only once

Add script to check person history before sending.

Updated over a year ago

If you have content in a particular stage of your Trigger Program that you only want to send to a person once, you can add some script to the Trigger Program to check back through a person’s history and make sure the email is only sent if they haven't received it before.

For example, if the second stage email in your cart abandonment program contains a coupon code with a short expiry, you might want to prevent that email being sent more than once, so the expiry message isn't always seen after the first send.

In this case, you would place the below script into the field on the Trigger Program labelled Script that controls whether 2nd action is run.

result.proceed = false;

var actions = person.actions;

var target_stage_sends = 0;

if (actions) {

for (i = 0; i < actions.length; i++) {

var action = actions[i];

// only check email queued actions

if (action.type && action.type == 1) {

// check trigger programs type, where b = cart, ba = browse, t = purchase

if (action.program && action.program.program_type && action.program.program_type == 'b') {

// check for trigger stage, where 1 = stage 1, 3 = stage 2, 5 = stage 3

if (action.program.action_index && action.program.action_index == 3) {

target_stage_sends += 1;

}

}

}

}

if (!target_stage_sends) {

result.proceed = true;

}

}

Alternatively, you could choose to only send the second stage email if someone has not received it within the past 6 months:

result.proceed = false;

var actions = person.actions;

var target_stage_sends = 0;

var now = new Date();

if (actions) {

for (i = 0; i < actions.length; i++) {

var action = actions[i];

// only check email queued actions

if (action.type && action.type == 1) {

// check trigger programs type, where b = cart, ba = browse, t = purchase

if (action.program && action.program.program_type && action.program.program_type == 'b') {

// check for trigger stage, where 1 = stage 1, 3 = stage 2, 5 = stage 3

if (action.program.action_index && action.program.action_index == 3) {

// check the date/time of the action

if (action.dt) {

var action_date = new Date(action.dt);

// check if matching action was within the last 6 months, in milliseconds

if ((now.getTime() - action_date.getTime()) < 15552000000) {

target_stage_sends += 1;

}

}

}

}

}

}

// only send if there were no matching actions

if (!target_stage_sends) {

result.proceed = true;

}

}

Did this answer your question?