I have some AMPScript writing records to a data extension. Using AMPScript I would like to store those records in a variable to access them in a javaScript function.

What is the best way to do it ?

<!DOCTYPE html>
VAR @sid, @skey, @jid, @listid, @batchid, @reason, @FieldList, @Rows, @i, @Row, @Name, @Value, @BackIn, @Subscriber, @Status
SET @sid = SubscriberID
SET @skey = _SubscriberKey
SET @jid = JobID
SET @listid = ListID
SET @batchid = _JobSubscriberBatchID
SET @reason = "Landing Page Unsubscribe"
SET @email = emailaddr                                      

SET @FieldList = BuildRowsetFromString(RequestParameter("FieldList"),",")
SET @Rows = Subtract(Rowcount(@FieldList),1)
SET @BackIn="false"

for @i = 1 to @Rows do
     Set @Row = Row(@FieldList, @i)
     Set @Name = Field(@Row,1)
     Set @Value = RequestParameter(@Name)

     if @Value=="true" then 
      Set @Value="true"   
      Set @BackIn = "true" 
      Set @Value="false" 


next @i                                                                   

if @BackIn=="true" then
  SET @Subscriber = CreateObject("Subscriber")
  SetObjectProperty( @Subscriber, "SubscriberKey",@skey)
  SetObjectProperty( @Subscriber, "Status", "Active" )
  SET @Status = InvokeUpdate(@Subscriber)

<script runat="server">

Platform.Load("core", "1");

var records = [];



1 Answer 1


You'd use the Variable.GetValue() function. Something like this:

<script runat="server">


  var BackIn = Variable.GetValue("@BackIn");
  Write("<br>BackIn: " + BackIn);


Reference: Using Server-Side JavaScript with AMPscript

  • Thanks @adam. I want to know how to write those records into an array after writing them to the dataExtension in AMPScript Dec 11, 2016 at 2:22
  • Maybe I could use BuildRowsetFromString Dec 11, 2016 at 2:28
  • It'd be easier to write the whole thing in SSJS. Here's the boilerplate that I use: gist.github.com/wvpv/19777e1167d6ac91e2e8 Dec 11, 2016 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.