Runtime verified Test scripts included

Syntax

GUID()  →  string

Parameters

This function takes no parameters. A call with an argument aborts the surrounding block with HTTP 422 while the rest of the page still renders.

Example

%%[
  VAR @token
  SET @token = GUID()
]%%
<input type="hidden" name="token" value="%%=v(@token)=%%">

Renders a value such as 1f3a9c02-5e7b-4d18-9a6c-2b40e8f7d135.

Store the result if the same identifier is needed twice — a second call returns a different value.

Return value

string — a 36-character identifier.

The value is an open domain, so there is no set of tokens to test against. What is fixed is the shape:

Property Value
Length 36 characters
Groups 8, 4, 4, 4, 12
Hyphen positions 9, 14, 19, 24
Hex digits lowercase
Braces none

Behaviour

The format is stable across samples. Four values produced in a single render were each 36 characters long, and slicing one of them into its five groups gave lengths of 8, 4, 4, 4 and 12 with a hyphen at each of positions 9, 14, 19 and 24.

There are no surrounding braces. Searching a sample for an opening or a closing brace returned 0 on the same value whose hyphen search returned 9 — so the 0 means absent, not found-at-the-start.

The hex digits are genuinely lowercase. The value equals its own lowercased form and does not equal its own uppercased form. A comparison that is merely case-insensitive would have matched both.

Every call returns a different value. Three assignments plus one inline call in the same render produced four distinct values, and comparing the first against the second and against the third both answered different. There is no per-render caching to rely on.

No argument is accepted. A one-argument call aborts its own block while the rest of the page continues to render, so the argument count is exactly zero.

Show test script
%%[
  VAR @b, @g1, @g2, @g3
  SET @b = RequestParameter("b")

  /* known-good control: renders on every request, so a run of HTTP 422s
     can be told apart from a broken deploy */
  OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))

  SET @g1 = GUID()
  SET @g2 = GUID()
  SET @g3 = GUID()

  OutputLine(Concat("--- G start ---"))
  OutputLine(Concat("G1=[", @g1, "]"))
  OutputLine(Concat("G2=[", @g2, "]"))
  OutputLine(Concat("G3=[", @g3, "]"))

  /* length, on three samples rather than one */
  OutputLine(Concat("GLEN=[", Length(@g1), "][", Length(@g2), "][", Length(@g3), "]"))

  /* every call differs, including an inline one in the same render */
  OutputLine(Concat("G12=[", IIf(@g1 == @g2, "same", "different"), "]"))
  OutputLine(Concat("G13=[", IIf(@g1 == @g3, "same", "different"), "]"))
  OutputLine(Concat("GINLINE=[", GUID(), "]"))

  /* case, proven in both directions: equal to its own lowercase form is
     also true of a case-insensitive comparison, so test the upper form too */
  OutputLine(Concat("GLOWER=[", IIf(@g1 == Lowercase(@g1), "already-lower", "has-upper"), "]"))
  OutputLine(Concat("GUPPER=[", IIf(@g1 == Uppercase(@g1), "same-as-upper", "differs-from-upper"), "]"))

  /* separator positions and the five groups between them */
  OutputLine(Concat("GSEP=[", Substring(@g1, 9, 1), "][", Substring(@g1, 14, 1), "][", Substring(@g1, 19, 1), "][", Substring(@g1, 24, 1), "]"))
  OutputLine(Concat("GGRP=[", Substring(@g1, 1, 8), "][", Substring(@g1, 10, 4), "][", Substring(@g1, 15, 4), "][", Substring(@g1, 20, 4), "][", Substring(@g1, 25, 12), "]"))

  /* no braces: 0 is the not-found answer, and the hyphen search proves it
     is not a match at the first position */
  OutputLine(Concat("GBRACE=[", IndexOf(@g1, "{"), "][", IndexOf(@g1, "}"), "]"))
  OutputLine(Concat("GHYPH=[", IndexOf(@g1, "-"), "]"))
  OutputLine(Concat("--- G done ---"))

  /* any argument at all: aborts this branch only */
  IF @b == "arity" THEN
    OutputLine(Concat("--- arity start ---"))
    OutputLine(Concat("GA1=[", GUID("x"), "]"))
    OutputLine(Concat("--- arity done ---"))
  ENDIF
]%%

Availability

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

See also