Runtime verified Test scripts included

Syntax

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

Parameters

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

Example

%%[
  VAR @total
  SET @total = Add(1, 2)
]%%
Total: %%=v(@total)=%%

Renders Total: 3.

Because a numeric string is accepted, adding zero is a compact way to turn a string field into a number before further arithmetic:

%%[
  VAR @qty
  SET @qty = Add(AttributeValue("Quantity"), 0)
]%%

Return value

number — the numeric sum of the two operands.

Every successful call rendered a bare numeric literal. There is no closed set of status tokens or sentinel values: the result is simply the sum.

Behaviour

Decimals and negatives work as expected. Add(1.5, 2.25) gives 3.75; Add(-5, 3) gives -2.

Numeric strings are accepted. Add("15", "27") gives 42, Add("3.14", 1) gives 4.14, and mixing forms as in Add(10, "5") gives 15.

Non-numeric input aborts the page. A non-numeric string (Add("abc", 1)), a boolean-like string (Add("true", 1)), an empty string (Add("", 1)), and a date value (Add(Now(), 1)) each abort the CloudPage with HTTP 422. None of them is coerced to zero, and none returns an error value you can test for — the page simply stops and everything already rendered is discarded.

No 32-bit truncation. Add(2147483647, 1) returns 2147483648, so results are not clamped at the signed 32-bit boundary.

Show test script
%%[
  VAR @b
  SET @b = RequestParameter("b")

  /* safe sweep: everything here is accepted and can share one request */
  IF @b == "safe" THEN
    OutputLine(Concat("Add(15,27)=[", Add(15,27), "]"))
    OutputLine(Concat("Add('15','27')=[", Add("15","27"), "]"))
    OutputLine(Concat("Add('3.14',1)=[", Add("3.14",1), "]"))
    OutputLine(Concat("Add(10,'5')=[", Add(10,"5"), "]"))
    OutputLine(Concat("Add(1.5,2.25)=[", Add(1.5,2.25), "]"))
    OutputLine(Concat("Add(-5,3)=[", Add(-5,3), "]"))
    OutputLine(Concat("Add(2147483647,1)=[", Add(2147483647,1), "]"))
  ENDIF

  /* each risky branch aborts the page: the start marker never renders */
  IF @b == "few" THEN
    OutputLine(Concat("few start"))
    OutputLine(Concat("Add(1)=[", Add(1), "]"))
    OutputLine(Concat("few done"))
  ENDIF

  IF @b == "many" THEN
    OutputLine(Concat("many start"))
    OutputLine(Concat("Add(1,2,3)=[", Add(1,2,3), "]"))
    OutputLine(Concat("many done"))
  ENDIF

  IF @b == "str" THEN
    OutputLine(Concat("str start"))
    OutputLine(Concat("Add('abc',1)=[", Add("abc",1), "]"))
  ENDIF

  IF @b == "bool" THEN
    OutputLine(Concat("bool start"))
    OutputLine(Concat("Add('true',1)=[", Add("true",1), "]"))
  ENDIF

  IF @b == "empty" THEN
    OutputLine(Concat("empty start"))
    OutputLine(Concat("Add('',1)=[", Add("",1), "]"))
  ENDIF

  IF @b == "date" THEN
    OutputLine(Concat("date start"))
    OutputLine(Concat("Add(Now(),1)=[", Add(Now(),1), "]"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next Yes, from API 67.0

See also