Expand my Community achievements bar.

SOLVED

Using targetData in Javascript

Avatar

Level 1

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;

 

kl28morr_0-1746020443389.png

kl28morr_1-1746020466660.png

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hey @kl28morr  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.


     Manoj
     Find me on LinkedIn

View solution in original post

9 Replies

Avatar

Community Advisor

Hi @kl28morr ,

Remove the @ symbol in Delivery JS.

It should be like 

targetData.segmentCode

 

Avatar

Level 1

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.

Avatar

Community Advisor

Hello @kl28morr 

 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
     Find me on LinkedIn

Avatar

Level 1

Hi @_Manoj_Kumar_  when I do that, I am getting "undefined" in the file name.

 

I have my delivery activity then a few other activities after, including enrichments, then finally doing a file export where I am referencing file name as you mentioned:

 

<%= vars.deliveryLabel %>_<%= formatDate(new Date(), "%4Y%2M%2D") %>.txt

 

the file name is "UNDEFINED_20250501"

Avatar

Community Advisor

@kl28morr  That means you Initial code isn't working


vars.deliverylabel = targetData.@deliverylabel;


     Manoj
     Find me on LinkedIn

Avatar

Level 1

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

 

This is where I am defining the targetData -

kl28morr_0-1746545178267.png

 

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

kl28morr_1-1746545226452.png

 

 

 

 

 

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

kl28morr_2-1746545277948.png

 

Avatar

Administrator

Hi @_Manoj_Kumar_ and @ParthaSarathy,

Would you be able to support @kl28morr further on this, or should we escalate it to our internal SMEs? Let me know what do you think.

Thanks!



Sukrity Wadhwa

Avatar

Correct answer by
Community Advisor

Hey @kl28morr  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.


     Manoj
     Find me on LinkedIn

Avatar

Level 1

Hi Manoh,

 

sorry for the delayed response. When you say make the value static - you mean to hardcode it manually? There is no way to pull the delivery label dynamically within each workflow? I am trying to avoid having to change it every time. Thanks!