JavaScript API generated delivery does not have access to targetData
Hello,
We are performing A/B testing on a pair of deliveries and trying to generate a winner delivery for the remaining population after a wait period for feedback. We have followed along with the solution in other Experience League posts, and can generate the delivery within the JS code activity as a copy of the winning test delivery via Duplicate(), post winner decision.
The issue that we are encountering is that we happen to use targetData as a source of a number of Target Mappings into broadLogRCP and substitutions into our emails. We haven't had issues with this in the few years that we have been using Adobe Campaign, but this is the first time that we have tried any deliveries from code. All others have explicitly been defined in Delivery activities. In this case, none of the targetData is recognized (we can see it in the transitions) so our broadLogRCP records are mostly empty, aside from Recipient and Delivery references, and our emails are produced with missing content.
Our original attempts followed a design pattern of defining the delivery in the code and then passing that into a Delivery activity with the Delivery option set to "Delivery defined in the transition".
We produce the delivery object in the code:
// logic prior to this point determines the winning A/B delivery, stored in 'winner'
// winner[0] is delivery id
// winner[1] is the delivery label
// winner[2] is the count of email clicks for the winning delivery
// create a new delivery object and initialize it by doing a copy of
// the winner delivery
var delivery = nms.delivery.create()
delivery.Duplicate("nms:delivery|" + winner[0]);
logInfo("Delivery duplicated from the winner.");
// append 'final' to the delivery label
delivery.label = winner[1] + " final" + formatDate(new Date(), "%2D%2M%2Y");
logInfo("Delivery label set: " + delivery.label);
//delivery.deliveryCode = winner.@deliveryCode;
//logInfo("Delivery code inherited: " + delivery.deliveryCode);
// link the delivery to the operation to make sure it will be displayed in
// the campaign dashboard. This attribute needs to be set manually here since
// the Duplicate() method has reset it to its default value => 0
delivery.operation_id = instance.operation_id;
delivery.workflow_id = instance.id;
logInfo("Delivery operation_id and workflow_id set.");
// adjust some delivery parameters to make it compatible with the
// "Prepare and start" option selected in the Delivery tab of this activity
delivery.scheduling.validationMode = "auto";
// tried 'auto' and 'manual', same behavior
logInfo("delivery.scheduling.validationMode: " + delivery.scheduling.validationMode);
delivery.scheduling.delayed = 0
delivery.validation.useBudgetValidation = false;
delivery.validation.useContentValidation = false;
delivery.validation.useExtractionValidation = false;
delivery.validation.useTargetValidation = false;
delivery.validation.useFCPValidation = false;
logInfo("Delivery parameters set.");
// save the delivery in database
delivery.save()
logInfo("Delivery saved.");
logInfo("delivery.id: " + delivery.id);
// store the new delivery Id in event variables
vars.deliveryId = delivery.id
logInfo("winner delivery configured");
Attempts to fire off PrepareAndStart(), or Prepare() and Play(), to launch the delivery in the script itself, fails with errors:
/*
04/24/2025 4:11:43 PM US_ALL_GW23Apr25T1 (6162280) wins with 5 email clicks vs the loser's 2
04/24/2025 4:11:44 PM Delivery duplicated from the winner.
04/24/2025 4:11:44 PM Delivery label set: US_ALL_GW23Apr25T1 final240425
04/24/2025 4:11:44 PM Delivery operation_id and workflow_id set.
04/24/2025 4:11:44 PM delivery.scheduling.validationMode: auto
04/24/2025 4:11:44 PM Delivery parameters set.
04/24/2025 4:11:44 PM Delivery saved.
04/24/2025 4:11:44 PM delivery.id: 6165100
04/24/2025 4:11:44 PM winner delivery configured
04/24/2025 4:11:44 PM Target preparation in progress...
04/24/2025 4:11:44 PM Waiting on replication: schema:'nms:delivery', id(s): '6165100'
04/24/2025 4:12:14 PM Initializing delivery process...
04/24/2025 4:12:14 PM Loading typology rules (step: javascript/preTarget)...
04/24/2025 4:12:14 PM Applying rule 'bcc address, email regex and domain allowlist check'.
04/24/2025 4:12:14 PM Applying rule 'OneClickUnsubscribe Interval'.
04/24/2025 4:12:15 PM XTK-170024 The temporary 'temp:delivery552-all' schema is not defined in the current context.
04/24/2025 4:12:15 PM XTK-170036 Unable to parse expression '@id=[temp:delivery552-all:@id]'.
04/24/2025 4:12:15 PM SOP-330011 Error while executing the method 'PrepareTargetImpl' of service 'nms:delivery'.
04/24/2025 4:12:15 PM SOP-330011 Error while executing the method 'PrepareTarget' of service 'nms:delivery'.
04/24/2025 4:12:15 PM SOP-330011 Error while executing the method 'Prepare' of service 'nms:delivery'.
04/24/2025 4:12:15 PM SCR-160012 Javascript: error while evaluating script 'pWKF4885/js266'.
*/
The temp table passed in from the prior activity is actually temp:extract4. We are not sure where the reference to "temp:delivery552-all" is coming from. My guess is that the same type of error is occurring when we pass it off to the Delivery activity, but it is not getting logged and it proceeds with the delivery anyhow (thus the missing targetData content).
Is there a way to explicitly define the targetData schema for a delivery to use via API? Or anything else that we are missing?
Thank you.




