LogoLogo
Documentation
Documentation
  • Getting Started
    • Introduction
    • Sign up to Developer Edition
    • Build Your First Agent
    • Developer Support
  • Core Concepts
    • Agent
      • Knowledge
      • Webhook
    • PII Masking
    • Sub-Agent
    • Intent
    • Workflow
      • Node
        • Input
        • Output
        • Loader
        • Display
        • API Node
        • Web Crawler
        • Table Write
        • Table Read
        • Ruleset
        • Upload Document
        • Javascript
        • Workflow
        • Loop
        • Document To Image
        • External Database
        • Storage Write
        • Storage Read
        • Fetch Document
        • Prompt
        • RAG Query
        • Vector Search
        • Emit Event
    • RAG
    • Model Hub
      • Entity Recognizers
    • Data Gateway
    • Rulesets
    • Code Snippets
    • Tables
    • Storage
    • Widget
  • Overview of GenAI
    • Introduction
    • Key concepts
      • Intent Classification
      • Inference
      • Generative AI Models
      • Large Language Models (LLMs)
      • Prompt Engineering
      • AI Agents
      • RAG (Retrieval Augmented Generation)
      • AI Workflow Automation
      • AI Agents vs LLM-based APPs
Powered by GitBook
On this page
  • Overview
  • What is a code snippet?
  • Understanding 'Input' in Code Snippets
  • When to Use Code Snippets?
  • Best Practices & Pitfalls of Using JavaScript Nodes
  • How to create a code snippet?
  • Key Takeaways for Developers
Export as PDF
  1. Core Concepts

Code Snippets

Overview

Like many low-code/no-code platforms, UPTIQ allows developers to inject custom code into workflows when required. The Workbench provides the ability to execute JavaScript code using Code Snippets, which can be embedded in workflows through the "Javascript" Node.

What is a code snippet?

A Code Snippet is a simple JavaScript function named main, which:

  • Takes input from the previous node in the workflow.

  • Stores that input in a special variable input, making it available throughout the function.

  • Outputs the processed result, which becomes the input for the next node in the workflow.

Understanding 'Input' in Code Snippets

Since every node’s output becomes the input for the next node, the data type of the input variable depends on the preceding node’s output:

  • If the previous node outputs a JSON object, input will be of type JSON.

  • If the previous node outputs a string or number, input will hold that respective type.

This flexibility allows developers to manipulate, transform, or filter data dynamically within workflows.

When to Use Code Snippets?

Developers can use JavaScript Nodes for: ✅ Data Formatting & Transformation – Convert data formats, adjust values, or prepare data for API calls. ✅ Basic Filtering – Remove unnecessary fields or extract key data before passing it to the next node. ✅ Applying Business Logic – Execute programmatic operations that aren’t natively supported by other workflow nodes. ✅ Custom Computations – Perform calculations or data aggregations before the AI agent processes the result.

Best Practices & Pitfalls of Using JavaScript Nodes

🚨 Avoid Overuse of JavaScript Nodes While JavaScript nodes add flexibility, excessive use can:

  • Reduce Workflow Readability – Business logic may become hidden inside code, making workflows harder to understand.

  • Complicate Debugging & Maintenance – Unlike visual nodes, JavaScript logic isn’t easily visible, which can make troubleshooting time-consuming.

  • Break the Low-Code Advantage – Workflows should remain as low-code as possible; use JavaScript only when absolutely necessary.

💡 Recommendation: Use JavaScript Nodes sparingly. Always check if the same transformation or filtering can be achieved with other workflow nodes before resorting to custom code.

How to create a code snippet?

There are two ways to create a Code Snippet:

1. From Config & Utils

  1. Navigate to Config & Utils → Code Snippet Tab.

  2. Click "Create Code Snippet."

  3. Enter a meaningful name for easy identification in workflows.

  4. Select the agent where the code snippet will be used.

  5. Click Save—the snippet is now available for workflows.

2. Directly from a JavaScript Node (Quick Method)

  1. Drag a JavaScript Node into the workflow.

  2. Click on the node to open the side panel.

  3. Click "Add Script"—this creates a new snippet and automatically assigns it to the agent.

  4. Save the snippet and later update it with the required business logic.

Key Takeaways for Developers

✅ Leverage JavaScript Nodes for targeted logic execution, such as data transformations and filtering. ✅ Ensure workflow readability by limiting JavaScript usage to essential cases. ✅ Use reusable Code Snippets to maintain modularity and avoid redundant script writing. ✅ Prioritize low-code workflow nodes whenever possible for better maintainability and collaboration.

By using Code Snippets effectively, developers can enhance workflow capabilities without compromising the benefits of low-code/no-code development in UPTIQ.

PreviousRulesetsNextTables

Last updated 4 months ago