skip to content

Function Call Syntax

JMeter's inline expression language: the call form, escaping a comma inside an argument, nesting one call inside another, and the handful of functions that show up in every real plan.

on this pageshow

explore

questions

5

In JMeter, how do you write a call to a built-in function such as __UUID?

level: juniorimportance: must knowfreq 78%

answer

  1. Same wrapper as a variable reference
  2. Built-in names carry a prefix
  3. Arguments are positional, comma-separated
  4. Parentheses are optional in one case
  5. A typo is not an error

basics

~10 s

JMeter function calls take the form ${__functionName(arg1,arg2)}. The double underscore marks a built-in, the parentheses hold comma-separated positional arguments, and a function that takes none may drop them: ${__UUID}.

solid answer

~40 s

A JMeter function reference is written `${__functionName(arg1,arg2)}` — the same `${...}` wrapper used for variables, with a leading `__` so built-ins cannot collide with variable names you invent. Arguments are **positional**, split on commas: `${__RandomString(8,abcdef)}` means eight characters drawn from `abcdef`, and there are no keyword arguments. A function that declares no arguments may omit the parentheses, so `${__UUID}` and `${__UUID()}` are equivalent. Names are case-sensitive: `${__uuid}` is not the `__UUID` function. If JMeter cannot resolve a reference — a misspelled function, an unset variable — it does not fail the run; it substitutes the reference text unchanged, so `${__UUId}` travels into the request literally. Calls work in almost any field of almost any element. This is Apache JMeter 6.0.0.

go deeper

for a junior

Recall the shape: dollar sign, brace, double underscore, name, optional parentheses with comma-separated arguments. Be able to write ${__UUID} and ${__RandomString(8,abcdef)} from memory without looking them up.

for a middle

Explain that arguments are positional, that parentheses may be dropped only for zero-argument functions, and that an unresolved reference is substituted verbatim rather than raising an error.

for a senior

Show that you check interpolation actually happened before trusting a plan — a request tab or a Debug Sampler on the first run — because JMeter passes a typo through as literal text into the payload.

for a principal

Own the convention across a team's plans: where functions are allowed to live, which are banned from hot fields, and how a review catches a reference that silently failed to resolve.

## One wrapper, two meanings JMeter has exactly one interpolation syntax: `${...}`. Everything between the braces is resolved when the surrounding field is evaluated. If the text names a **variable**, JMeter substitutes that variable's value; if it names a **function**, JMeter runs the function and substitutes what it returns. ``` ${__functionName(arg1,arg2,arg3)} ``` Every function shipped with JMeter begins with a double underscore — `__UUID`, `__counter`, `__RandomString`, `__timeShift`, `__urlencode`, `__P`, `__V`. The prefix is a naming convention rather than a parser rule, and its whole job is to keep built-ins from colliding with names you invent yourself. In practice you can read a reference at a glance: a leading `__` means a call, anything else means a variable lookup. ## Arguments are positional Whatever sits inside the parentheses is split on commas into positional arguments. There are no keyword arguments and no named defaults — position is the only thing that identifies an argument. - `${__RandomString(8)}` — length only. - `${__RandomString(8,abcdef)}` — length, then the pool of characters to draw from. - `${__RandomString(8,abcdef,SUFFIX)}` — length, pool, and a variable to store the result in. A trap worth learning on day one: `${__RandomString(8)}` with no pool draws from the whole of Unicode, so you get eight arbitrary characters rather than eight letters. Almost every real use supplies the second argument. ## Parentheses are optional only when there are no arguments `__UUID` and `__threadNum` declare no parameters, so `${__UUID}` and `${__UUID()}` are equivalent, as are `${__threadNum}` and `${__threadNum()}`. The moment a function takes one argument the parentheses become mandatory. The reverse is not true. *Optional* arguments still occupy positions, so you cannot simply leave the tail off. `__timeShift` accepts four or five parameters and rejects anything shorter, which is why its documented examples read `${__timeShift(,,PT10S,,)}` — the unused slots are still typed out as empty text between commas. ## Names are case-sensitive Functions, variables and properties are all case-sensitive in JMeter. `${__uuid}` and `${__Uuid}` are not the `__UUID` function; they are variable lookups that will almost certainly miss. Variable *names* are trimmed of surrounding spaces before lookup, so `${__Random(1,63, LOTTERY )}` stores into `LOTTERY`, not into a name with spaces around it. ## An unresolved reference is not an error This is the behaviour that catches everyone once: | You write | JMeter resolves | The field receives | | --- | --- | --- | | `${__UUID}` | the `__UUID` function | e.g. `c69e0dd1-ac6b-4f2b-8d59-5d4e8743eecd` | | `${__UUId}` | no such function, no such variable | the literal text `${__UUId}` | | `${ORDER_ID}` before `ORDER_ID` is set | no such variable | the literal text `${ORDER_ID}` | A reference JMeter cannot resolve is handed straight back, and nothing is logged at error level. A typo therefore travels all the way into the request body as literal text instead of surfacing as a start-up failure. The habit that costs nothing: look at one sampler's request tab, or drop in a Debug Sampler, the first time a new field uses a function. ## Where a call can go - Almost any text field of almost any element — sampler paths, body data, header values, timer delays, assertion patterns. - Not usefully on the Test Plan element itself: thread variables are not set up there, so `__threadNum` and the variable-reading functions do not work, while `__P`, `__property`, `__intSum`, `__longSum`, `__time` and the scripting functions do. - Not `__threadNum` inside a config element such as User Defined Variables — config elements are processed from a separate thread. One structural detail explains a great deal of surprising behaviour later: **each occurrence of a call in the plan is compiled into its own function instance.** Two fields that both contain `${__counter(TRUE,)}` do not share a sequence; they are two independent counters that happen to be spelled the same way.

  • What does JMeter put in the field when a referenced variable was never defined?
    The reference text itself, unchanged. `${ORDER_ID}` with no such variable renders as the literal seven-plus characters `${ORDER_ID}`, and nothing is logged at error level. The same rule covers misspelled function names, which JMeter treats as variable lookups that miss.
  • Why does ${__RandomString(8)} produce unreadable characters?
    The second argument is the pool of characters to draw from, and it is optional. With no pool, `__RandomString` draws from the whole of Unicode, so you get eight arbitrary characters. Supply the pool — `${__RandomString(8,abcdefghijklmnopqrstuvwxyz)}` — whenever the value has to be readable or ASCII-safe.
  • Can a user-defined variable be named with a leading double underscore?
    Nothing stops you, but do not. The `__` prefix exists precisely so built-in function names occupy a namespace of their own; naming a variable `__total` makes every reader stop and check whether it is a call. Reserve the prefix for JMeter's own functions.

saying these in an interview costs you the question

  • Says JMeter function names are case-insensitive, so ${__uuid} works
  • Thinks a misspelled function name aborts the run with an error
  • Writes ${functionName} without the double-underscore prefix
  • Believes JMeter function arguments are named rather than positional
  • Assumes every function must be written with parentheses
open as a page

In JMeter, what happens when a function argument contains an unescaped comma?

level: middleimportance: must knowfreq 62%

basics

~20 s

JMeter splits a function's argument list at every unescaped comma, so the comma becomes an extra argument. Write it as a backslash followed by a comma to keep it inside one argument; otherwise the call fails its parameter-count check.

open as a page

In JMeter, ${A${N}} does not resolve. How do you look up a variable whose name is built at run time?

level: middleimportance: should knowfreq 48%

basics

~10 s

JMeter has no nested-variable syntax. Wrap the composed name in the __V function instead: ${__V(A${N})} evaluates A${N} to A1 first, then returns the value of the variable called A1.

open as a page

In a JMeter HTTP Request's Body Data field, how do you generate a unique order id per request?

level: seniorimportance: should knowfreq 54%

basics

~20 s

Put the function in the Body Data field itself. ${__UUID} yields a fresh type-4 UUID on every evaluation; ${__counter(TRUE,)} yields a per-thread sequence; ${__threadNum} is fixed per thread and only unique inside its own Thread Group.

open as a page

What does JMeter's Function Helper Dialog give you when you click Generate?

level: juniorimportance: nice to knowfreq 24%

basics

~10 s

Generate builds the ${__function(...)} call string from the argument boxes you filled in, escapes commas outside a nested reference, copies the result to the clipboard, and runs the call once for a preview.

open as a page