iterating over an array while creating profile scripts | Community
Skip to main content
New Participant
March 18, 2022

iterating over an array while creating profile scripts

  • March 18, 2022
  • 2 replies
  • 1987 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Employee
March 24, 2022

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.

 

Hope that is helpful.

sonalipaiAuthor
New Participant
March 25, 2022

@ryanr7:

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

Gokul_Agiwal
New Participant
March 23, 2022

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 

sonalipaiAuthor
New Participant
March 23, 2022

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;

Gokul_Agiwal
New Participant
March 23, 2022

Glad that it's working now, Thanks you.