1

currently i am using this ampscript for lookuprows:

%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i

set @lookupValue = AttributeValue("lookupField") /* value from attribute or DE column in send context */
set @lookupValue = "whee" /* or a literal value */
set @numRowsToReturn = 0 /* 0 means all, max 2000 */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    var @DEColumn1, @DEColumn2
    set @row = row(@rows,@i) /* get row based on counter */
    set @DEColumn1 = field(@row,"DEColumn1")
    set @DEColumn2 = field(@row,"DEColumn2")

    ]%%

    Row %%=v(@i)=%%, DEColumn1 is %%=v(@DEColumn1)=%%, DEColumn2 is %%=v(@DEColumn2)=%%

    %%[ 
  next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%

Since i do not know the value of i (count) in advance, the output gives me a number of rows based on the lookup search. Now i want to use all returned output rows values i javascript variables (exasperated).

It Is like, each data extension column will have a set of values meanings, if output is 6 rows, I will have 6 different values of each column.

I know how to display these values on a page by ampscript but how to save all the possible values in javascript variables?

1 Answer 1

2

I am giving three solutions because I am not sure exactly what you mean:

Solution 1: Utilize the SSJS LookupOrderedRows() Function instead of AMPScript:

var dataRows = Platform.Function.LookupOrderedRows('dataExtensionName',1,'LastName ASC','Company','exampleCompany');

This will give you everything already inside of a JS context. You can also use the Rows.Retrieve() function if you need more complex filters.

Solution 2: Utilize the Get.Value() SSJS:

<script runat=server> var example = Platform.Variable.GetValue('@AMPscriptValue'); </script>

you would just put the SSJS content block after the variable is defined and the above would add the AMPScript value into the SSJS variable.

Solution 3: If you mean Javascript (Client-side) instead of SSJS

<ctrl:var name=JSVar />

Using the above inside of your JS to set the var would bring that varaible out from SSJS and into JS.

For example:

<script>

    var myVar = <ctrl:var name=JSVar />;

</script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .