Automating workflow on record creation or update

Options

Hi,

I just started using Xano and I'd like to learn if it's possible for me to trigger a workflow on the creation or update of a record in the database? One of my uses cases requires the data in a field to be used in an (external) API call to receive a response that can be saved in another field.

For example: let's say I have a field called "country" and another called "capital_city". When a record is created, the data saved in "country" is used to make an API call that will return the capital city, which will then be saved to the "capital_city" field.

Can someone walk me through how I could accomplish this? I'm not sure whether this use case fits a function or a task? I haven't upgraded to a paid account yet, so I don't really understand how tasks differ from functions.

Thank you! I appreciate your time!

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @mikhaeel

    I would add this logic to the function stack where the record is being created. Xano allows you to define whatever logic, or "trigger". The Function Stack performs logic in a linear fashion and you can pass data between functions in the form of variables. So you might have:

    1. Add Record to table to add country
    2. External API Call using table.country
    3. Edit Record to table by updating capital_city

    If you're looking for the best way to get up to speed in Xano, I recommend attending an upcoming Orientation. You can sign up here: https://go.xano.co/orientation-officehours

  • Guillaume Maison
    Guillaume Maison Member ✭✭
    Options

    @mikhaeel unless you're updating your DB by hand, directly in the DB interface, every Insert/Update/Delete is specifically made into a function stack from an API Endpoint.
    It means that you can add a function for that each time you modify data in one table or anoher.
    My suggestion would be the following :
    1. you create a function that takes 2 parameters : tableName, editMode ("insert/update/delete")
    1bis. you can add a third and fourth parameter that can be the "record before" and "record after"
    2. in this function, you set as many if-Then conditionals as there're table names.
    3. inside each conditional, you add other conditionals, depending on the editMode and you set your functions to do what is needed to do.
    4. each time you modify a data for a table, you call this function with the according parameters.

  • mikhaeel
    mikhaeel Member
    Options

    Thanks for your input guys. Much appreciated.

    After spending a little time testing functions and going through some trial and error, I think I understand how to get it done.