AMPscript Function Calls
Call the AMPscript at the location in the email message, landing page, or SMS message where you want the result of the script to appear. All AMPscript code and functions must be surrounded by open and close delimiters, or the code will be ignored by the system. Function calls will execute even if outside of a scripting statement, such as SET or IF. When using brackets before and after AMPscript delimiters, include spaces between those brackets and delimiters.
Function calls outside of an AMPscript block must be introduced by the opening delimiter %%= and terminated by the closing delimiter =%%.
This AMPscript example demonstrates how to include multiple AMPscript references inside a single set of delimiters:
Function calls within an AMPscript block should not include the opening (%%=) and closing (=%%) delimiters.
Function output can also be referenced in script and function calls. In the case of functions, this is implemented through nested function calls. For example:
To prevent infinitely looping AMPscript calls, you can’t call AMPscript functions recursively and will receive an error: 104 - RecursiveScriptError. Recursive conditions count against the subscriber error limit threshold or disposition the subscriber send as Errored/NotSent. This error applies to email, SMS, and push notifications but doesn’t apply to CloudPages.
This sample illustrates the minimum syntax necessary to declare an AMPscript block.
This sample illustrates the complete syntax used to declare an AMPscript block.
The AMPscript block must be closed in the same syntax that opens it. For example, if you open a block using <script>, you must close it with </script> and not ]%%.
The table below demonstrates the similarities between standard AMPscript delimiters and server-side delimiters.
|Standard AMPscript Delimiter||Tag-based AMPscript Delimiter|
|%%[||<script runat=server language=ampscript>|
|%%[[type=post;name=blockname]||<script runat=server language=ampscript executioncontexttype="Post" executioncontextname=blockname>|
|%%%%||<script runat=server language=ampscript />|
Functions accept any of these input types: