How can I use a javascript script in a workflow to create variables to be used in an email delivery



I'd like to create a new variable which will be a copy of a target level variable, create a new variable which is a substring and then use the new variable in a delivery.

Something like:

var mainImageHeaderText_var = instance.currentOrder.localContent.singleProperty.mainImageHeaderText_A;

logInfo("mainImageHeaderText_var = "+mainImageHeaderText_var);

var vars.test = mainImageHeaderText_var.substring(mainImageHeaderText_var.indexOf("WSTART")+7, mainImageHeaderText_var.indexOf("WEND")-1));

The first line returns "undefined"

The reason I can't do this via an enrichment is that the string length may exceed 255 characters.