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 Feb 19 '14 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 Feb 20 '14 at 9:43
  • That is good to know. Thanks for the follow-up. – Mac Feb 20 '14 at 13:28

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.

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.