Return String Value based on Boolean True or Fale
Watching some tutorials, I was able to successfully return (using an addon) a boolean value, true or false, based on whether the item is saved/liked by the authenticated user or not. But on the front-end no code tool I am using, Bravo Studio, I need to accompany this with a string value; for example:
if _likes: false then also return mystring: default
if _likes: true then also return mystring: active
Basically, I want to be able to return another addon (?) value, such as "mystring" right after the response for "_likes" as seen above and set the value for this string to either default or active based on the value of the _likes boolean.
Can you please help guide me on how I can accomplish this? Thanks
Best Answer
-
Do this in the function stack! After your query, make a for...each loop (under data manipulation) and augment each "item" with an additional path using "update variable" and "set".
The function stack is where Xano really shows its quality. Getting that extra power out of it is a common topic in our daily State Change Pro office hours. We focus on the hardest 5% of a given no-code project.
Answers
-
@Ray Deck , Thank you so very much! I am such a newbie, this is very helpful, and I will follow your guidance and give it a try and update results here... thank you again
-
Hello @Ray Deck ! Thank you so much again for your help. @brian and @Michael Udinski were very kind to help me through this (addon + custom update variable) process in a recent Bravo Studio / Xano joint workshop! We did a for each loop in the function stack and created (& updated) a new variable to be included in the return response and assigned a value to it based on a conditional if check.
Above was for a main /get request.
Now I am trying to duplicate it for a /get/{id} request, the only difference here is that instead of an array a single object item is being returned so I am not able to do a for each loop and simply doing a conditional if doesn't help me either..
3 Screenshots attached.
1- Regular get list works beautifully!
2- Get specific item request /id - gets the response I need but does not correctly update the variable
3- 3rd screenshot shows that on my Get specific item request, with input id, /{id}, even though the “bookmarks” is “true” the “state” is set to “default” instead of “active”
The only difference between /get and /get/id is that one returns an array other one returns a single item, and therefore I am not able to do a for each loop
In other words, I am successfully able to set this new variable called “state” to “active” or “default” based on whether the “bookmarks” is “true” or “false” in my main /GET (get all) api call but not on my /GET/ID specfic item call..
-
Somehow, automagically, I got this working :) All I did was to delete and start over again and simply recreated the same function stack, and same addons and same exact conditional if's and then's and update variables, and it works now, but what I did is 100% identical to what I did before, oh well, magic!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback