Calculating total hours worked - Should I use Custom Functions?

Options

Hi!

I want my API to return the number of "hours worked", based on some business predicates, using the data being stored in related records.

I'm sure it can be done with Xano, but I'm unsure about what component/feature to use.

Should I use a Custom Function? Or should I use something different?

In Airtable, I'd typically use a Formula field.

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    It can be done in a couple of different ways depending on the details of your case.

    Can you share some more information about how the data structure is build and in how many related tables the data about "hours worked" is stored?

  • Ambroise
    Ambroise Member
    Options

    I have a table "Traveler" and another one called "TimeCategorization", which contains the actual worked hours.

    I want to return Traveler.hoursWorked as a computed value. In airtable, I'd use a Formula field. In Xano, I understand there is no such thing and I should rather do the calculation on all API endpoints where I want to get the hoursWorked value.

    Now, I guess using a Custom Function to do this calculation is one way to go, I'm unsure if I'll have several APIs that will need it, but I'd rather write something that can be reused later easily.

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Actually if you want to access TimeCategorization from Traveler you need to add it as an addon in your query Traveler query all records (so yes you need to do this either in background task or endopit).

    By adding TimeCategorization as an addon to Traveler via table relation you will gain access to all the TimeCategorization fields. If Traveler is related to more than TimeCategorization you can connect them all as a list via addon and then sum up hours from all of them by creating a new variable for example.

    There are plenty of methods to do that and this is just one of them. If I would know more about your project then maybe I would be able to guide you more specifically. Let me know if that helped.

    Btw, I'n offering consultation so if you have trouble with some other things in Xano and would like to speed things up, drop me an email: pmagdanski@gmail.com

  • Ambroise
    Ambroise Member
    Options

    Thanks Pawel, that does help!