Expand my Community achievements bar.

Direct Mail Output failing to Add <%= message.cellId %> to output syntax

Avatar

Level 2

Hello, The DM Delivery output script is consistently failing to compile when adding any type of variables to the output script (Ex: <%= vars.campaignId %>_<%= vars.workflowId %>_<%= vars.lastSync %>). I've also tried updating the script syntax in the DM template then echoing it to the recurring delivery in the campaign but still failing with errors below. One think I noticed is that whatever variable we add to the script output file, it’s always defaulting to <%= message.cellId %> in the output file external config. The following is the output name I want to achieve ==> DirectMail_2022-10-19_12-48-34-000_3262771_3453765_2210191231.txt. Any feedback would be greatly appreciated.

 

Screenshots:

Soph75_0-1668006416390.pngSoph75_1-1668006434152.png

 

Thanks,

Soph

12 Replies

Avatar

Community Advisor

Hi @Soph75 ,

Configure the below script in Delivery activity's script tab

var query = xtk.queryDef.create(<queryDef schema="nms:operation" operation="select"><select><node expr="@id"/><node expr="@internalName"/></select><where><condition expr={"@id = '"+instance.operation_id+"'"}/></where></queryDef>); var eventExistss = query.ExecuteQuery(); for each (var eventT in eventExistss.operation){ instance.vars.CampaignId = eventT.@id;}

delivery.variables._var[0].stringValue=instance.vars.CampaignId;

delivery.variables._var[1].stringValue=instance.id;

ParthaSarathy_0-1668153846613.png

And in Delivery Property > Variable Tab,

Add > Name: CampaignId > ok

Add > Name: workflowId > ok

ParthaSarathy_1-1668154039470.pngParthaSarathy_2-1668154055941.png

In Extract File name,

DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D_%02H-%02N-%02S") %>-000_<%= variables.CampaignId %>_<%= variables.workflowId %>.txt

ParthaSarathy_3-1668154122922.png

Once you run the workflow, you will get the expected file name

ParthaSarathy_4-1668154189515.png

 

And if you want to add few more variables in file name, you can follow the same step,

In delivery tab,
delivery.variables._var[2].stringValue=<Pass the variable (eg, lastSync)>;

In Property>Variable> Add > Name: lastSync

Extract file name,
DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D_%02H-%02N-%02S") %>-000_<%= variables.CampaignId %>_<%= variables.workflowId %>_<%= variables.lastSync %>.txt

 

 

 

 

Avatar

Level 2

Hi Partha, Thanks for the JS scripts, it's very helpful to achieve the output file script calculation. I've applied the scripts and variables to the recurring delivery but campaignId/deliveryId is not sequential as expected, the output of the two variables need to be incremental values every time I deploy a new campaign (Ex: 3262772_3262771, 3262773_3262772, 3262774_3262773...etc). does it need to be defined somewhere else to achieve the desired output? (See screenshot).

 

Soph75_0-1668207679216.png

 

 

Thanks,

Soph

Avatar

Community Advisor

Hi Soph,

Try replacing delivery activity script tab code with below script and re-run the workflow,

var query = xtk.queryDef.create(<queryDef schema="nms:operation" operation="select"><select><node expr="@id"/><node expr="@internalName"/></select><where><condition expr={"@id = '"+instance.operation_id+"'"}/></where></queryDef>); var eventExistss = query.ExecuteQuery(); for each (var eventT in eventExistss.operation){ instance.vars.CampaignId = eventT.@id;}

delivery.variables._var[0].stringValue=instance.id;

delivery.variables._var[1].stringValue=instance.vars.CampaignId;

Avatar

Level 2

Hi Partha, I've replaced the script code provided below but running into an error with the delivery. 

var query = xtk.queryDef.create(<queryDef schema="nms:operation" operation="select"><select><node expr="@id"/><node expr="@internalName"/></select><where><condition expr={"@id = '"+instance.operation_id+"'"}/></where></queryDef>);
var eventExistss = query.ExecuteQuery();
for each (var eventT in eventExistss.operation){ instance.vars.CampaignId = eventT.@id;}
delivery.variables._var[0].stringValue=instance.id;
delivery.variables._var[1].stringValue=instance.vars.CampaignId;

 

 

Error:

11/13/2022 10:29:00 PM SCR-160012 Javascript&colon; error while evaluating script 'DM_Test_Campaign_1/deliveryRecurring5'.
11/13/2022 10:29:00 PM Index out of range for object on path 'var'
11/13/2022 9:42:20 PM SCR-160012 Javascript&colon; error while evaluating script 'DM_Test_Campaign_1/deliveryRecurring5'.
11/13/2022 9:42:20 PM JST-310000 Error while compiling script 'DM_Test_Campaign_1/deliveryRecurring5' line 4: delivery.variables_var is undefined.

 

 

 

Thanks,
Soph 

Avatar

Level 2

Hi Partha, I was able to run the last script provided after a small adjustment but not producing the expected result in the output file name (See script and variable configured in the delivery).

 

Delivery Activity script:

 

var query = xtk.queryDef.create(<queryDef schema="nms:operation" operation="select"><select><node expr="@id"/><node expr="@internalName"/></select><where><condition expr={"@id = '"+instance.operation_id+"'"}/></where></queryDef>);
var eventExistss = query.ExecuteQuery();
for each (var eventT in eventExistss.operation){ instance.vars.CampaignId = eventT.@id;}
delivery.variables._var[0].stringValue=instance.id;
delivery.variables._var[1].stringValue=instance.vars.CampaignId;

 

 

Output script:

 

<%@ include option='itrvExportCampaignFileDirectory' %>DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D") %>_<%= formatDate(new Date(), "%02H-%02N-%02S") %>-000_<%= variables.campaignId %>_<%= variables.workflowId %>_<%= variables.lastSync %>.txt

 

 

Soph75_0-1668444336820.png

 

 

File output still not sequential.

Soph75_0-1668447860903.png

 

 

 

 

Thanks,
Soph

 

Avatar

Community Advisor

Hi @Soph75 

 

You can save the variables in a OptionVariable and keep on reusing the same OptionVariable after updating it at the end.

 

For instance :-

for saving the variable into OptionVariable (Script to in END activity):-

setOption('CampaignId', instance.vars.newCampaignId);

 

for retrieving the value from OptionVariable (Script to in START activity):-

vars.newCampaignId = getOption('CampaignId');

Then once you retrieve the OptionVariable, you can increment it as desired. eg : newCampaignId = CampaignId+1; newWorkflowId = workflowId +2;

This you can call in your workflow as :

<%@ include option='itrvExportCampaignFileDirectory' %>DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D") %>_<%= formatDate(new Date(), "%02H-%02N-%02S") %>-000_<%= variables.newCampaignId %>_<%= variables.newWorkflowId %>_<%= variables.lastSync %>.txt

Which will always increment the variables and push into the output file.

Hope this helps you find a fix.

 

Regards

Avatar

Level 2

Hi Akshay, Thanks for you input and suggested solution but the OptionVariable isn't producing the CampaignId that is supposed to be mapped to concatenated field in the data extract (See screenshot below). The same value of campaignID must be calculated in the output script variables.

Soph75_0-1668624092941.png

 

Expression: @campaignIIId+"_"+@deliveryIIId+"_"+@eventIItime

 

 

Thanks,
Soph

Avatar

Community Advisor

Hi @Soph75 

 

Apologies if I was not clear, I suggested to store the workflow variables such as CampaignID and workflowID is some variables and then store them in optionVariables so that we can reuse them anytime later. 

Then once you retrieve the OptionVariable, you can increment it as desired. eg : newCampaignId = CampaignId+1; newWorkflowId = workflowId +2;

 

So suppose CampaignId = 001 and workflowId = 004, the first file would have these numbers and also the same would be stored in the OptionVariables. Now when the workflow runs for the second time and these values are retrieved from the optionVariables, they would go for an increment as defined. (newCampaignId  = 001 + 1 and newWorkflowId = 004+2) and hence the file name would have these new incremented value and same would be store in the OptionVariable for reuse.

 

You can call that variables in your Output file to modify the name as suggested by @ParthaSarathy  and i hope the file would be named in an incremental manner.

 

Regards

Avatar

Community Advisor

Hi @Soph75 ,

Modify Output file name script as,

DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D_%02H-%02N-%02S") %>-000_<%= variables.workflowId %>_<%= variables.CampaignId %>.txt

Avatar

Level 2

Hi Partha, If I remove Option <%@ include option='itrvExportCampaignFileDirectory' %> from output script there's no destination folder to drop the output files when they run.

 

Thanks,
Soph

Avatar

Community Advisor

Hi @Soph75 ,

Above script will helps to provide the output file name in the format mentioned in question. In addition to the file name script you can add option/destination folder directory to place the file in the destination folder.

Avatar

Level 2

Hi Pratha, The above script worked but still not incrementing values of CampaignId when running multiple recurring deliveries. I'd like to suggest using "vars.lastSync" variable instead to output file naming. See below steps taken of implementation scripts. Please if that is the correct path to achieve it.

 

 

Advanced Script 

 

Soph75_1-1670448685224.png

 

vars.campaignId = sqlGetInt("SELECT O1.iOperationId FROM XtkWorkflow W0 JOIN NmsOperation O1 ON (O1.iOperationId = W0.iOperationId) WHERE (((W0.iWorkflowId = '" + instance.id + "') AND (W0.iDisabled = 0)))");
logInfo("campaignLabel: " +vars.campaignId);

vars.workflowId = instance.id;
logInfo("Workflow Id: " + vars.workflowId);

vars.lastSync = formatDate(new Date(), "%2M/%2D/%4Y");
logInfo("Execution Time: " + vars.lastSync);

 

Delivery Script:

 

var query = xtk.queryDef.create(<queryDef schema="nms:operation" operation="select"><select><node expr="@id"/><node expr="@internalName"/></select>
<where><condition expr={"@id = '"+instance.operation_id+"'"}/></where></queryDef>);
var eventExistss = query.ExecuteQuery();
for each (var eventT in eventExistss.operation){ instance.vars.lastSync = eventT.@id;}
delivery.variables._var[0].stringValue=instance.id;
delivery.variables._var[1].stringValue=instance.vars.lastSync;

 

 

Variables:

Soph75_2-1670447819440.png

 

 

output file name script:

 

<%@ include option='itrvExportCampaignFileDirectory' %>DirectMail_<%= formatDate(new Date(), "%4Y-%2M-%2D") %>_<%= formatDate(new Date(), "%02H-%02N-%02S") %>-000_<% variables.lastSync %>.txt

 

 

 

Thanks,
Soph