Releases And Snippets

Conditionally Update Booleans | Customer Corner

Summary

Xano's no-code platform allows you to build and deploy backend services for web and mobile applications without writing code. One common use case is conditionally updating a Boolean field (true/false) in your database based on the input received from your API. This guide will walk you through the process step-by-step, using Xano's recently added granular control over conditional operators.

Step 1: Create a Nullable Boolean Input

  1. In your Xano project, navigate to the API section and create a new API endpoint (or edit an existing one).
  2. Add a new input field of type "Boolean" and give it a name (e.g., "active").
  3. By default, the Boolean input will have two values: true and false. However, we want to make it nullable, so click the "Nullable" checkbox and save the input.

Step 2: Set Up the Conditional Update

  1. In the "Edit Record" function, create a new input field separate from the database link input. This is because we don't want to use the exact schema from the database.
  2. In the expression builder, add a new condition using the "If" statement.
  3. In the condition, use the triple equals operator (`===`) to check if the input value is exactly equal to `null`.
  4. If the condition is true (input value is null), leave the "Then" clause empty. This means the Boolean field won't be updated.
  5. In the "Else" clause, add an action to update the Boolean field with the input value.

Step 3: Test the Conditional Update

  1. Open your database and note the existing Boolean values for a few records.
  2. In your API endpoint, test the conditional update by passing different values for the Boolean input:
  • Pass `null` or leave the input empty to confirm that the Boolean field remains unchanged.
  • Pass `true` or `false` to update the Boolean field accordingly.
  1. Verify the changes in your database after each API call.

By following these steps, you can now conditionally update Boolean fields in your database using Xano's no-code platform. The key is to leverage the triple equals operator (`===`) to check for an exact match with `null`, allowing you to skip the update when no value is provided.

For non-technical users and developers alike, this approach simplifies the process of handling conditional updates for Boolean values, saving time and effort in building and deploying backend services. Enjoy the power and flexibility of Xano's no-code platform!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free