# How to create a function that returns database data?

**URL:** https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027
**Category:** Questions about Thunkable X
**Tags:** firebase
**Created:** [September 15, 2019, 2:28am UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027 "2019-09-15T02:28:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![temi.giwa](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/temi.giwa/32/40397_2.png) [@temi.giwa](https://community.thunkable.com/u/temi.giwa)
#### Post date: [September 15, 2019, 2:28am UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/1 "2019-09-15T02:28:54Z")

</div>

Hi  
I’m new to Thunkable and want to use functions. I’ve looked at the documentations and it hasn’t really helped (it only states what you can do not how you can do it)

I’m trying to create a function that takes in a variable and returns a value. The value can either be nothing (because the data wasn’t found) or a property of the results.

The problem is that it’s highly inconsistent.

This is the setup I have now and sometimes it will return a value and other times it wont. Even when I’ve changed absolutely nothing.

I’ve tried the if \_\_\_ return as well but I don’t know how to get it to work?

How exactly do you use functions? And how do you use them with RealTimeDB

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/5/35ef0c9841a05988e0c479c25c10e12212f2110d.png)

---

<div class="post-metadata">

### Author: ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)
#### Post date: [September 15, 2019, 3:31am UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/2 "2019-09-15T03:31:25Z")

</div>

Hi, @temi.giwa! 👋  
Try removing the **if** block 😄

---

<div class="post-metadata">

### Author: ![temi.giwa](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/temi.giwa/32/40397_2.png) [@temi.giwa](https://community.thunkable.com/u/temi.giwa)
#### Post date: [September 15, 2019, 11:53am UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/3 "2019-09-15T11:53:03Z")

</div>

Thanks @kartik14 I tried that and it worked!

Then 10 mins later tested the app again and it stopped working. It returns the variable workout\_status 's original value

---

<div class="post-metadata">

### Author: ![temi.giwa](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/temi.giwa/32/40397_2.png) [@temi.giwa](https://community.thunkable.com/u/temi.giwa)
#### Post date: [September 15, 2019, 1:19pm UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/4 "2019-09-15T13:19:33Z")

</div>

So after much struggling decided to use the Firebase web API based on this answer: [How to filter/sort values on Firebase](http://community.thunkable.com/t/how-to-filter-sort-values-on-firebase/75036/6)

So much more flexible

---

<div class="post-metadata">

### Author: ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)
#### Post date: [September 15, 2019, 1:39pm UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/5 "2019-09-15T13:39:00Z")

</div>

So, if I helped you,

**Please mark my post above as the solution ✅ …**  
Then the forum will clear this topic from the unsolved topics, and move it to solved topics 😉

* * *

# Thanks! 😊

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 12:08pm UTC](https://community.thunkable.com/t/how-to-create-a-function-that-returns-database-data/227027/6 "2024-11-08T12:08:59Z")

</div>


