Firstly, I apologise - I am a beginner with JavaScript and SSJS. I am trying to send an email with a CTA button that has an url to an external page, which will prepopulate values from a DE on the form.

This is the html I have, I don't get any errors on the email but the values does not pass through. I am using the %%=v(@url)=%% as link url. Thank you in advance!


SET @FirstName = FirstName
SET @LastName = LastName
SET @Email = Email
SET @MailingPostalCode = MailingPostalCode
SET @cID = Id
SET @Title = Salutation
SET @Mob = MobilePhone

<script runat="server" language="JavaScript" executioncontexttype="Post" executioncontextname="test">


       function getRandomString(leng)
         var str = "";
                     for(var i = 0; i < leng; i++)
           str += parseInt(Math.random() *9);
         return str;
       var version = "";
       var ttl = Variable.GetValue("@Title");
       var ph = Variable.GetValue("@Mob");
       var sfid = Variable.GetValue("@cId");

        version = "2";
        version = "3";

       var fn = Variable.GetValue("@FirstName");
       var s = Variable.GetValue("@LastName");
       var e = Variable.GetValue("@Email");
       var p = Variable.GetValue("@MailingPostalCode");
       var mystring = "fn="+ fn + "&s=" + s + "&e=" + e + "&p=" + p;

       //if(version == "2")
       //   mystring = "ttl="+ttl+"&fn="+ fn + "&s=" + s + "&e=" + e + "&p=" + p;
       //if(version == "3")
          mystring = "ttl="+ttl+"&fn="+ fn + "&s=" + s + "&e=" + e + "&p=" + "3058" + "&ph=" + ph +"&sid=" + sfid;

       var encString = getRandomString(3);//random 3 at start
       var sep = "";
       for(j = 0; j < mystring.length; j++) {

         encString = encString + sep + getRandomString(1) + mystring.charCodeAt(j) + getRandomString(1);
         sep = "-";
       encString = encString + getRandomString(3); //random 3 at end

       var url = encString+"&v="+version+"&utm_medium=email&utm_source=company&utm_campaign=brand|generic|comp-mpe&utm_content=brand-edm&utm_term=loyalty|own"

       Variable.SetValue("@url", url);    

I don't think you need to use any execution context for your ssjs. Your script isn't executing because you have those properties in your script tag (it's not erroring for the same reason either).

So just use:
<script runat="server">

instead of
<script runat="server" language="JavaScript" executioncontexttype="Post" executioncontextname="test">

Also you have some random closing div tags in your script at the end. These: </div></div>. I'd remove those as well.

  • Thanks for your reply Josh! I've made those changes but the url that populates ends with "nannannan...etc" - Do you know why I might be receiving this "Not a Number" value? The form does not populate either but directs fine to the page with no error. – s3329893 Aug 5 at 6:52
  • In your getRandomString you are using parseInt() function which parses a string argument and returns an integer. But you aren't parsing a string, the leng variable is already an integer. Read more here. Not really clear on what your code is trying to achieve overall, so can't offer any suggestions there. – Josh de Blank Aug 6 at 4:50

Are you using the RedirectTo AMPscript function with your hyperlink?

This function is required when using the HTML hyperlink tag in emails when the hypertext reference (href) attribute is either an attribute or a variable and the hyperlink is a tracked email link.


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.