Expand my Community achievements bar.

iterating over an array while creating profile scripts

Avatar

Level 1

I am trying to code a profile script that looks for some query parameters.  At some point after I have split the query parameters into an array, how should i iterate over the array to find the query parameter I need.  I have tried using for, forEach, while loops...all show some syntax error although the function works perfectly fine when ran on the browser console.

5 Replies

Avatar

Community Advisor

Hi @sonalipai 

As you said it's working fine in bowser console however not in profile script, Is it possible you to put your code here in dummy form so we can troubleshoot 

Avatar

Level 1

Hello @Gokul_Agiwal :

Found the solution, apparently iterators do not work in profile scripts that is because adobe targets does not like javascripts with more than 2000 js instructions in the script.  The easiest way was to use a split() function.

Example like 

var text = "How are you doing today?";
varcount = text.split("are").length -1;

Avatar

Community Advisor

Glad that it's working now, Thanks you. 

Avatar

Employee Advisor

Looks like you found a solution. There is a pretty decent built in method also just to share:

var param = page.param('PARAMETERNAME');

If you know the name of the page query parameter you can reference it directly in a profile script like above. 

The little "available tokens" widget on the right side of the edit script pane shows some of these.

 2022-03-24_15-16-39.jpg

Hope that is helpful.

Avatar

Level 1

@Ryan_Roberts_:

That was my initial solution.  But unfortunately, there is no good documentation around page.param.

How should page.param be used if there are multiple same name params in the query string.  I was assuming that page.param would return an array, but i think it returns a string.

 

Thanks