Target page params as array | Community
Skip to main content
jezwn
December 10, 2021
Solved

Target page params as array

  • December 10, 2021
  • 1 reply
  • 1761 views

I have this targetPageParamsAll() in the AEM page which would return the user groups as an array.

targetPageParamsAll = function() { var userGroups = "everyone,test1,test2,beta1"; var userGroups = userGroups.split(","); return { "userGroups": userGroups } };

 

Attaching a screenshot on the available mbox parameter w.r.t userGroups below,

 

My requirement is to check whether the user belongs to a certain group and return that group name from the script. With the above highlighted, would I need to check each of these individual params(ranging from 0 to 16) and return for true cases.

Is it possible I can get the userGroup as an array instead(var userGroups = mbox.param('userGroups');) and check whether the user belongs to a particular group(eg:beta1)? Some recommendations on this would be appreciated. Thanks!

Best answer by jgrubbs

I suppose you could try passing the array as a stringified object, such as:

   return { userGroups: JSON.stringify(userGroups) };

 

And then parse it as an array in the profile script:

var userGroups = JSON.parse(mbox.param('userGroups'));

 

1 reply

jgrubbs
jgrubbsAccepted solution
December 10, 2021

I suppose you could try passing the array as a stringified object, such as:

   return { userGroups: JSON.stringify(userGroups) };

 

And then parse it as an array in the profile script:

var userGroups = JSON.parse(mbox.param('userGroups'));

 

Khushboo_Kalia
Adobe Employee
Adobe Employee
March 2, 2022

@jgrubbs The similar approach actually worked for me, but I need it as a list to create an exclusion in recommendation -

Will it work for my use case? I have posted it separately over here -

https://experienceleaguecommunities.adobe.com/t5/adobe-target-questions/can-we-pass-multiple-values-as-mbox-parameter/td-p/442704

Any help would be appreciated, thanks!