My objective is to insert the subscriberkey into a data extension on JavaScript onclick event. I do not see any viable documentation that works. I've tried passing AmpScript variables to Javascript and I get a 500 error.

I've tried some basic JavaScript insert below from the documentation and get a 500 error.


<script runat=server>

  var arrContacts =  [

var birthdayDE = DataExtension.Init("birthdayDE");

SSJS is executed in the backend. Hence once the page is loaded, it will not execute before the page is refreshed. You should create a JSON Code Resource, where you put your AmpScript.

You can then call that Code Resource URL in JS on your Cloud Page, passing values as e.g. Request Parameters. It should read your GET variables, and use appropriate code to upsert this data to a data extension.

You can then return the status code of this request in JSON, for your JS to parse and present on the page making the request.

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.