Optimize posting data on Xano

Hello,

I have an array with integer values (see below)
image

Each value then creates a row (including user_id & goals_id) on my database on Xano.

As the workflow on the screenshot shows (see below), the only solution I found is to generate an API request to create a row. Is there a way to create multiple request within ONE request? Thank you!!

Hi, If I understand well you can use our loop system !

You can make the loop iterate through your selection variable, and put your request block inside the loop so it will be executed for every item in the variable. You will be able to bind to the loop context

1 Like

Hi, you should put everything in a object variable containing all your needed data and pass this to Xano. Then you can deal with the list of objects on backend. This way you will not call the same API several times.
However @Alexis method will work anyway :slight_smile: but using loop is highly recommended anyway.

2 Likes

@Alexis
Thank you for your answer and Loom!

I tried what you show in the video but it copies the same value (11) as many times as there are items in the array (10).

Here is the setup:


Do you know why it does not loop through the array but instead remains on the first item [0]?

Hi @Dominic - Thank you for your help.

Never done that. I’m a bit of a rookie and afraid I don’t full grasp how to do that. Would you be able to show this on a visual manner? I think that’d help a lot :pray:

Thanks

Hi, that’s because you bound the wrong thing (sorry maybe I did the same in my demo), you bound the items 0 of the list, instead of the current item (key “item” above)

Hi @Alexis - it works thank you !

Hi @Alexis

I have added additional information (amount, date) to be sent through the API

.

When I bind to “Loop_obj.loop.index” on each line (goals_id,target_amount,goal_deadline) I always get the same “current value” (here 2 in this loop sequence). Is there a thing here to bind to the correct value ?

Thank you

Hi, the explorer will show the same index every time you try to bind but the value of item and index will change for every iteration of course (except if there is a bug)

So here you should bind loop->item->amount to target_amount for example, and probably loop->item->date to goal deadline

1 Like

Thank you !

Hi Alexis,
Me again :smiley: It’s a follow-up to the question so I reactivate it - again-.

I have a problem when I send the Goals_id to Xano and could not find how to solve it.

I will try to explain as clear as I can:

On Xano, I have a “goal” table with goal names, goal_id (i.e. Goal_ID 1=Buy something; Goal_ID 2=Eliminate debt, etc.) and, each goal specificity (about 5 columns).

I have a second table named “user goal details”. This stores all goals a user has chosen along with many other information. This table has a relationship to the “goal table”. So in the “user goal details” table, the goal “Buy something” is just named “1”).

Now on WeWeb, the user can select a goal (through checkbox) with the text label (e.g. Buy something or Eliminate debt) but the “value” in Weweb is the Goal ID (1, 2, etc.)

Now if I put “Buy something” in the value, when I send the data to the “user goal details” table through the API on Xano, it’s rejected because Xano expects the Goal ID “1” in its language for “Buy something”.

Given I reuse the checkbox value in the process, the Goal ID “1” does not make sense to the user. So, I would like to send “Buy something” to Xano instead of the Goal ID (“1”).

Is there a way I can build a mapping table on Weweb or another trick? I hope it’s clear and sorry if it’s not :sweat_smile:.

Thank you again for all your help!

Can you show me how do you manage the checkbox ? I dont understand where are you displaying the raw values (1, 2, …) to your users.

If you are using a select you can have a label different from the value and so the user will see the label but you will display the value. You can also create your own formula and use a switch to resolve every possible value (if you have like 5 different goals you can do it easily) to return the corresponding label for a given value, if you need to display it somewhere else

Like a getGoalLabel(goalId)

1 Like

Hi Alexis,

The Checkbox includes a textbox that is bound to the “goal names” tables so it displays the “right” name to the user.


Now, the checkbox itself has the value that corresponds to the Goal ID (see in objective name below).

The value of the checkbox (i.e. goal ID) feeds an array of objects including 3 information: Goal ID, Amount, and Date. When the user selects the goal, it feeds one information in the array of objects:

On the next page, I have a datagrid where the user is asked to provide further details for each goal he/she selects. That’s when the rest goes into the array of objects. This is where I struggle because the user sees the raw values (1,2, etc). FYI (there will be about 10 goals in total with all very specific information)

After that, the user is directed to the sign in page where all user information, user goals and goal details are sent to Xano via the API.

I like the checkbox because I can get the value of the variable and do custom states. I tried with the select but did not succeed there.

Thank you!

As I said, you can create your own formula to it translate the number to the label, and use it inside your datagrid

With a switch you can enter every variant you have switch(myVariable, myValue1, myLabel1, myValue2, myLabel2, ...)

If it change change and/or you dont want to maintain this formula, you can try to do something more dynamic by loading your table containing all the goals and doing a formula that find the label in the list for a given goal id

1 Like

Thanks ! I tried the “switch” formula and almost works.

The switch formula on itself works but, when landing on the datagrid page, it remains “11”, “12”, etc. Now, if I remove the formula, and copy-paste it again, it correctly displays the correct label (i.e. Buy something, Eliminate debt").

Do you know why it does not work during the load?