Scripts
The Scripts feature in LemmeBuild allows you to write and manage custom JavaScript code that interacts with your database or other workflow blocks. With scripts, you can perform complex operations, such as pulling data, manipulating it, or even interacting with external APIs. Scripts give you the flexibility to handle advanced tasks that go beyond the capabilities of standard blocks, returning results back into the workflow for further processing.
Key Features
- Custom Operations: Create custom JavaScript scripts to handle tasks like data manipulation, complex logic, and API interactions that require more control than standard blocks provide.
- Database Interaction: Use scripts to directly query or update your database using the
$db
object, allowing seamless integration of your data within the workflow. - Seamless Integration: Return the results of your custom scripts back into the workflow, enabling the next steps to utilize the output, whether it’s data or processed information.
Using Scripts in Workflows
You can write JavaScript code directly within the Script Block of a workflow, or you can create reusable scripts in the Scripts section. Once a script is saved, you can reference and use it across multiple workflows, making your code modular and reusable.
Importing a Script
To use a saved script in a workflow block, you can import it using the following format:
import { } from 'scripts:script_name';
This allows you to execute custom logic and advanced operations within the workflow by calling pre-written scripts.
Example
Create a Script
In the Scripts section, you can write JavaScript to fetch user data from your database:
// Example Script: Fetch user data
const users = await $db.execute('SELECT * FROM users');
return users;
Import the Script into a Workflow
Within the workflow, use the Script Block to call your saved script:
import { } from 'scripts:fetchUserData';
const users = await fetchUserData();
console.log(users);
This script pulls user data from the database and returns it, allowing the workflow to process or display it as needed.
Why Use Scripts?
Scripts provide flexibility when you need to perform advanced operations that are beyond the scope of standard workflow blocks. They allow for custom logic, database queries, external API calls, and more, making them essential for building powerful, dynamic workflows. With scripts, you can extend the capabilities of LemmeBuild and create highly customized solutions tailored to your workflow's specific needs.
By leveraging the Scripts feature, you can enhance the power of your workflows with custom JavaScript, enabling deeper integrations and more advanced functionality in LemmeBuild.