Using targetData in Javascript | Community
Skip to main content
Level 2
April 30, 2025
Solved

Using targetData in Javascript

  • April 30, 2025
  • 1 reply
  • 1106 views

Hello,

I am trying to set a variable using targetData in Javascript.  My code looks like this but I keep getting "targetData not defined" error message.  I've confirmed my targetData and the alias is correct.  Any ideas?  I will need to use the vars.deliverylabel in a file name in a file export activity.

 

// Get delivery label
vars.deliverylabel = targetData.@deliverylabel;

 

 

Best answer by Manoj_Kumar

Do you mean where I am defining the targetdata is not working?

 

This is where I am defining the targetData -

 

This is how i am setting the vars (right after the above enrichment using a Javascript activity)

 

 

 

 

 

I also removed the "@" symbol per ParthaSarathy comment and then calling it in my file export file name:

 


Hey @kristenco4  Since your target dimension has multiple records. The targetData won't work in this.

 

You will have to split the audience based on deliveryLabel and then make that value static.

1 reply

ParthaSarathy
Community Advisor
Community Advisor
April 30, 2025

Hi @kristenco4 ,

Remove the @ symbol in Delivery JS.

It should be like 

targetData.segmentCode

 

~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups
Level 2
April 30, 2025

I tried this but still getting the same error:

 

// Get delivery label
vars.deliverylabel = targetData.deliverylabel;

 

04/30/2025 10:55:24 AM SCR-160012 Javascript: error while evaluating script 'WKF14851/js'.
04/30/2025 10:55:24 AM JST-310000 Error while compiling script 'WKF14851/js' line 3: targetData is not defined.

Manoj_Kumar
Community Advisor
Community Advisor
May 1, 2025

Hello @kristenco4 

 I believe you are trying to name the file based on the delivery Label. If that is your use-case then do this.

Use <%= vars.deliveryLabel %> in the file name.

 

 

Manoj  | https://themartech.pro