Runtime verified Differs from official docs Test scripts included

Syntax

Add(number1, number2)  →  number
2 arguments — exactly

Parameters

Name Type Required Description
number1 number Yes First operand
number2 number Yes Second operand

Exactly two arguments. Pass numeric literals or numeric variables: a number written as a string breaks the render in Next.

Example

%%=Add(15, 27)=%%

Renders 42.

Decimals keep their fractional part:

%%=Add(1.5, 2.25)=%%

Renders 3.75.

Return value

number — the sum of the two operands.

Every call that rendered gave a bare number. There is no set of special values to test for.

Behaviour

Exactly two arguments. An email that calls Add(1) or Add(1, 2, 3) cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.

Results wrap at the 32-bit limit. Add(2147483647, 1) renders -2147483648, not 2147483648. Keep sums below 2,147,483,647 or do the arithmetic before the value reaches the email.

Numeric strings break the render. Add("15", "27"), Add("3.14", 1) and Add(10, "5") all save, but the email preview then fails with HTTP 500 and no message. Convert string values before adding them.

A negative first operand broke the render too. Add(-5, 3) saved but the preview failed with HTTP 500, so a negative literal as the first argument was not shown to work in Next.

Non-numeric input fails. Add("abc", 1), Add("true", 1), Add("", 1) and Add(Now(), 1) each make the preview fail with HTTP 500. Nothing is coerced to zero.

Show Next test script
<!-- Marketing Cloud Next test script for Add. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[42] got=[%%=Add(15,27)=%%]</p>
<p>c2 expect=[3.75] got=[%%=Add(1.5,2.25)=%%]</p>
<p>c3 expect=[-2147483648] got=[%%=Add(2147483647,1)=%%]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add("15","27")=%%

<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add("3.14",1)=%%

<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add(10,"5")=%%

<!-- email 4: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add(-5,3)=%%

<!-- email 5: expect that the save is rejected (HTTP 400) -->
%%=Add(1)=%%

<!-- email 6: expect that the save is rejected (HTTP 400) -->
%%=Add(1,2,3)=%%

<!-- email 7: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add("abc",1)=%%

<!-- email 8: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add("true",1)=%%

<!-- email 9: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add(Now(),1)=%%

<!-- email 10: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Add("",1)=%%

Differs from official docs

  • Negative first operand. The official reference allows positive and negative operands. In Next, Add(-5, 3) saved, but the email preview failed with HTTP 500 (one probe). Details
  • 32-bit wrap-around. The official reference names no size limit. In Next, Add(2147483647, 1) renders -2147483648. Details

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also