Is there anyway to place Server Side JavaScript within AMPScript?

For example i have a JavaScript function getLink() which returns a link and i want to place it within a AMPscript TreatAsContent function like the below.


Obviously this won't work as i probably need to exit the AMPScript, enter JS,exit JS then renter AMPSCript. But not sure of the correct syntax to do this. Anyone have an idea how to do this?

At the moment i pass the JavaScript value returned from getLink() to AMPSCript.

//Declare AMP script variable
%%[var @link]%%

//Get link and pass to ampscript @link variable
<script runat=server>
var link= getLink();

//Place link in a <a> tag
<a href="%%=TreatAsContent(@link)=%%">Link</a>
  • Does that existing code work and you are just looking for a better way to do it? I would expect the Variable.SetValue("link", link"); like to instead read: Variable.SetValue("@link", link"); in order for it to be able to be referenced outside of JS correctly.
    – Mac
    Commented Feb 19, 2014 at 13:13
  • @Mac Yeah my current solution works was just looking for a better solution. And it seems you don't have to specify the @ in the Variable.SetValue("link", link); when referencing the AMPscript variable.
    – JCS
    Commented Feb 20, 2014 at 9:43
  • That is good to know. Thanks for the follow-up.
    – Mac
    Commented Feb 20, 2014 at 13:28

1 Answer 1


No - this is not possible. You would want to exit and enter the different languages. See documentation

Side note - if you are attempting to use SSJS in email, don't. It's very slow and will produced poor send speeds.

You must log in to answer this question.

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