I am really new to SSJS but what I am trying to achieve is to pass some parameters in the URL from an email and capture them in the cloud page and then save that data into a DE using SSJS.

At the moment I have written the following:

%%[var @SubscriberKey,@email,@date
SET @SubscriberKey=RequestParameter('SubscriberKey')
SET @email=RequestParameter('email')
SET @date = NOW()]%%

<script runat="server">
Platform.Load("Core", "1.1.1");
var request = {}
var SubscriberKey = Variable.GetValue("@SubscriberKey");
var email = Variable.GetValue("@email");
var date = Variable.GetValue("@date");    
var SSJSentries = DataExtension.Init("SSJS entries");

  var row = {};
              row.EmailAddress = request.email;
              row.SubscriberKey = request.SubscriberKey;
              row.date = request.date;
                Write("<br><br>DE row: " + Stringify(row));
              try {
                // attempt to add a row
                SetVar("rowAddResults", SSJSentries.Rows.Add(row));

 catch (e) {
  Write("<br>Exception: " + e);


When I redirect to the cloud page from the email I get the following message:

My Subscriber Key Value [email protected] 9/26/2019 5:04:50 AM

DE row: {"EmailAddress":null,"SubscriberKey":null,"date":null}
Exception: Object expected: SetVar

I can pass the params OK after the GetVariable but I don't know how to write to request the values & insert them in the Data Extension.

What did I miss?



1 Answer 1


First, as Cameron Robert stated, you can easily do this via UpsertData or InsertData, etc. inside AMPscript.

Now, the issue in your current code is that you created a request object, but never filled anything in it, so when you try to fill in the row object via request.email you are pulling nothing as there is nothing inside it.

I would change it to be:

var row = {};
          row.EmailAddress = email;
          row.SubscriberKey = SubscriberKey;
          row.date = date;

As the email, SubscriberKey and date vars are already defined above. There is no need to push them into another object first (request). From there it should function as expected.

As for AMPscript, you could literally remove all the javascript and replace it with a single function:

var @SubscriberKey,@email,@date
SET @SubscriberKey=RequestParameter('SubscriberKey')
SET @email=RequestParameter('email')
SET @date = NOW()
UpsertData('SSJS entries', 1, 'SubscriberKey', @SubscriberKey,'Email', @email, 'date', @date)
  • 1
    Hiya, thanks so much! I managed to change the Row but it still doesn't inject. Message I get is: <br>Exception: Object expected: SetVar. I am out of my comfort zone with SSJS so this was a little self training exercise but i got stuck along the way. I know i could use amp script but i wanted to get a bit of hands on exercises with small SSJS exercises
    – Wallace
    Sep 26, 2019 at 13:59
  • sorry missed that, need to change it to Variable.SetValue() not SetVar() as that is not a predefined function in SFMC SSJS. Sep 26, 2019 at 14:38

You must log in to answer this question.

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