Expand my Community achievements bar.

SOLVED

storing an array of strings in a profile attribute

Avatar

Level 1

Hi,

I have the following profile script:

user.arrayTest

if (mbox.name == "kevins_mbox") {
  user.setLocal("arrayTest", ["hello", "world"]);
  return user.getLocal("arrayTest");
}

However, when trying to use the array in a JS offer via: ${user.arrayTest}

The final output looks like this: [hello, world] - i.e. the quotes are missing and a JavaScript error is thrown.

According to this document: http://microsite.omniture.com/t2/help/en_US/tnt/pdf/js_expression_cheat_sheet.pdf

"Script Profile Parameters are found under the mboxes/profiles tab. You 
can write Javascript programs that return any Javascript type (String, 
integer, array, etc)"

Can someone tell me what I am doing wrong here?

Many thanks,

Kevin

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

With just the snippet above, quotation marks should not be getting removed.

However, they would not be printed out if you were trying to display/use one of the elements of the array. i.e. you would need to something like this get the quotation marks printed out:

['"hello"', '"world"']

It would be helpful to have some more context.

What is the JavaScript error you are getting?

Can you be more specific about what you are doing with ${user.arrayTest}?

Is it possible to share the page on which you are trying to implement this custom code? a link to the page, the page code, etc.

 

- Carey

View solution in original post

3 Replies

Avatar

Level 3

Hi Kevin,


Maybe if you fixed the quotes the output would look right.

 

Thanks,

Avik

Avatar

Level 1

Hi Avik,

Thanks for your reply. I am passing the array with quoted elements. Point is, that is not what is returned from the TnT engine (missing the quotes)

Avatar

Correct answer by
Former Community Member

With just the snippet above, quotation marks should not be getting removed.

However, they would not be printed out if you were trying to display/use one of the elements of the array. i.e. you would need to something like this get the quotation marks printed out:

['"hello"', '"world"']

It would be helpful to have some more context.

What is the JavaScript error you are getting?

Can you be more specific about what you are doing with ${user.arrayTest}?

Is it possible to share the page on which you are trying to implement this custom code? a link to the page, the page code, etc.

 

- Carey

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----