Search code examples
javascriptsalesforcessjssalesforce-marketing-cloud

Using SSJS variables in my client side JS


Using Salesforce Marketing Cloud I am trying to retrieve a list of records using SSJS like this:

<script runat=server>  
        Platform.Load("Core","1");
        var dataRows = Platform.Function.LookupRows('Companies','name','Acme Ltd');
        if(dataRows && dataRows.length > 0) {
             for(var i=0; i<dataRows.length; i++) {
                  Platform.Response.Write(dataRows[i]["city"]);
             }
        }
</script>

I would like to use the returned dataRows in my client side javascript so I can manipulate and print the data out as required.

However even doing something as simple as console.log(dataRows) returns a 500 internal server error.

Can someone advise?


Solution

  • There is no direct solution but you can try a workaround. Wherein, you store the variable in ampscript using "Variable.SetValue("",);" And then get this value in js using Variable.GetValue("");