Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorBuild a scenario
vars and const
The product generator now needs two kinds of shared values: one catalog id for the whole run, and one product id reused inside each product event. Writing the expressions twice would calculate two different results.
Use const and vars to calculate a value once, give it a name, and reuse it with $name.
The result we want
The catalog id should stay fixed. The product id should change, but the id inside productUrl must match it:
{"catalogId":"CAT-00","productId":"PROD-00","productName":"Wireless headphones","productUrl":"/products/PROD-00"}
{"catalogId":"CAT-00","productId":"PROD-01","productName":"Mechanical keyboard","productUrl":"/products/PROD-01"}
Reuse calculated values
Products from one catalog
generators:
- name: products
config:
maxEvents: 3
const:
catalogId: =seq(format=CAT-%02d)
vars:
productId: =seq(format=PROD-%02d)
value:
catalogId: $catalogId
productId: $productId
productName: =cycle(Wireless headphones, Mechanical keyboard, Studio microphone)
productUrl: =concat(/products/, $productId)
Press Try it and compare the three events.
const.catalogIdis calculated once when the generator starts, so every product usesCAT-00.vars.productIdis calculated again for every event, producingPROD-00,PROD-01, andPROD-02.$catalogIdand$productIdcopy those calculated values intovalue.=concat(/products/, $productId)uses the current event’s product id in the URL.
Helpers are not output fields
Only fields under value appear in the event. Names under const and vars are available while the event is built, but stay hidden unless value copies them.
If you remove productId: $productId from value, productUrl still works because $productId remains available. The standalone productId field simply disappears from the output.
Choose the right lifetime
- Use
constfor one value shared by the generator run, such as a catalog, batch, or tenant id. - Use
varsfor a value shared only inside one event, such as an id used in both a key and payload.
Placing the same expression in two fields does not share its result. Name it once when the fields must agree.