run_javascript
RunJavaScript is a campaign node that executes custom business logic inside the ResultFly runtime. The node consumes the current State and campaign context, computes a result, and applies approved changes to declared variables before the flow continues. It exists to adapt campaign rules on the fly—not to replace API integrations or external services.
Summary
- Placement: Mid-flow.
- Context: Client and backend apps (executes inside the managed runtime).
- Visual: No.
- Level: Advanced.
- Purpose: Run bespoke campaign logic that depends on declared State without involving external APIs.
What RunJavaScript Does
- Runs as part of the campaign flow, between other nodes.
- Executes in a controlled ResultFly environment with access to the same State the rest of the campaign uses.
- Receives the live State as input and produces calculated values or State updates through sanctioned operations.
- Keeps all logic server-side; nothing runs in the user’s browser.
RunJavaScript vs API Integrations
| Use API Integrations when… | Use RunJavaScript when… |
|---|---|
| Data originates in external systems (CRM, POS, loyalty backends). | Logic depends purely on the campaign’s current State. |
| Business rules must live in the brand’s backend or middleware. | Marketers need to adjust rules frequently without redeploying backend code. |
| A server-to-server conversation is required (webhooks, file drops, event ingestion). | The flow needs inline calculations, conditional branching, or normalization before choosing the next node. |
RunJavaScript complements APIs: external events and service calls bring data into ResultFly, while RunJavaScript shapes decisions using that data inside the runtime.
Working with State
The node reads declared variables across all scopes:
state.user.*— user-level data shared across campaigns.state.campaign.*— campaign-specific variables.state.app.*— variables tied to the current app or game.
Updates must follow State rules:
- Only declared variables may change.
- System fields (for example
state.sessionIdor runtime pointers) are off-limits. - New variables cannot be created during execution; declare them before launch.
RunJavaScript applies mutations using the same mechanisms as other nodes, ensuring consistency with the State model.
Typical Use Cases
- Bonus calculations. Combine multiple variables (spend, tier, streak) to determine how many points to award.
- Advanced branching. Evaluate layered conditions to decide which storyline, prize, or limiter applies.
- Data shaping. Transform external event attributes or user inputs into normalized State values before downstream nodes consume them.
Limitations and Guarantees
- Code executes in an isolated, sandboxed environment controlled by ResultFly.
- No direct network access; outbound calls are blocked unless explicitly provided by another node.
- Execution time is limited to keep the campaign responsive; long loops or blocking logic will fail.
- RunJavaScript is part of the deterministic campaign runtime—every execution is audited alongside other nodes.
What RunJavaScript Is NOT
- It is not a replacement for the brand’s backend or microservices.
- It is not an API endpoint or webhook target.
- It is not a substitute for external events or server-to-server integrations.
- It is not a loophole to bypass State rules or create ad-hoc storage.
Relationship to Other Concepts
- Identity. Determines which user’s State the node reads and updates.
- External Events. May trigger a flow that includes RunJavaScript, ensuring external signals feed into on-platform logic.
- State & Variables. Provide the structured data the node consumes and mutates.
- API Integrations. Handle communication outside ResultFly, delivering the data that RunJavaScript leverages during execution.
Last updated on