1

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>
<html>
<head>
</head>
<body>
%%[
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" 
     else
      Set @Value="false" 
     endif

     InsertData('ENT.TEST_PrefChanges1','MemberID',@skey,'ProgramID',@Name,'Subscribed',@Value,'Modified',DateParse(NOW(),1))

next @i                                                                   

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

<script runat="server">

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

var records = [];

function(){}
</script>

</body>
</html>
0
0

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

<script runat="server">

  Platform.Load("Core","1.1.1");

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

</script>

Reference: Using Server-Side JavaScript with AMPscript

3
  • Thanks @adam. I want to know how to write those records into an array after writing them to the dataExtension in AMPScript – user1100023 Dec 11 '16 at 2:22
  • Maybe I could use BuildRowsetFromString – user1100023 Dec 11 '16 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 – Adam Spriggs Dec 11 '16 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.