# Do IF... Then, Case, Do While, Loop in Bubble workflow

**URL:** <https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756>\
**Category:** Database\
**Created:** [March 13, 2018, 4:32pm UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756 "2018-03-13T16:32:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [March 13, 2018, 4:32pm UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/1 "2018-03-13T16:32:03Z")

</div>

Please tell me how to do some basic programming techniques below in Bubble workflows:

1. IF…Then
2. Case … End case
3. Do While (loop) to do some things of scan record by record in a table in Bubble database.
4. make query to do some action as query in SQL database:
  - Make the view to join some tables to view and report data
  - Add new, Insert, edit and delete records

Thanks!  
Regards,  
Long

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [March 14, 2018, 7:52am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/2 "2018-03-14T07:52:16Z")

</div>

1. Use “Only When”

![image](https://us1.discourse-cdn.com/bubble/original/3X/0/6/06df398433ac2c81b5060e734aed008397b6e682.png)

1. Just use multiple “only whens” to do the various tests. We don’t have this explicitly, but it is doable.

2. This is “Schedule API Workflow” - so you run a “subroutine” on a list of records. Note that this is “a priori” in that you need to know the list of records in advance, you can’t (easily) do

3. 

“Joins” are implicit in the Bubble Database by the use of Custom Fields that link tables.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/2/2/22924ef3b7bfc087be31d9f28c5e8e8274980a3e.png)

This is one-to-many join between Table A and Table B.

![image](https://us1.discourse-cdn.com/bubble/original/3X/4/a/4aab686f69655be6b9b6109539c0d977967732de.png)

CRUD is via workflow actions…

![image](https://us1.discourse-cdn.com/bubble/original/3X/9/c/9cfde78614b58c04b49521075ca8ef569ec943e8.png)

---

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [March 15, 2018, 2:01am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/3 "2018-03-15T02:01:09Z")

</div>

Thanks MigelG!

It is very clear and helpfull with me, but how to do it In case primary key is two fields ?

Regards,  
Long

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [March 15, 2018, 1:32pm UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/4 "2018-03-15T13:32:41Z")

</div>

In your search, test for the two fields existing.

---

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [March 16, 2018, 1:35am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/5 "2018-03-16T01:35:48Z")

</div>

Hi,

No, I mean the primary key is a pair (not individual one by one), please see example below

![image](https://us1.discourse-cdn.com/bubble/original/3X/6/7/678c0eecfce27740718226ce655014fbf0f49aaa.png)

Primary key in Contract\_Device table is Contract\_Number + Device\_Model then it is foreign key in Device\_Assign table, please tell me how to:

1. Manage the primary key in a pair in Contract\_table (Contract\_number + Device\_Model) is not doublicate
2. How to access Contract\_Device table via foreign key from Device\_Assign table, because I see in Define Primary Key option in Bubble setting do not allow us option primary key is a pair as picture below.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/6/1/613e776c906f5311b792a072c7321befa76153ca.png)

Thanks & Regards,  
Long

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [March 16, 2018, 11:51am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/6 "2018-03-16T11:51:04Z")

</div>

1. You manage it in “code” not in the database.

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/1/3/134c5ec2ef5779e67d8df189319956181cf92cb1.png)

1. That is somewhat confusing, it is NOT anything to do with Primary and Foreign Keys. It is just what field shows up when you link two tables.

In bubble, the way you link two tables is not via Keys. It is effectively via embedding the objects (things) in other objects (things). So sort of Object Relational. At least at the front end.

So… You have your Device Assign… in which you embed your parent. And remove the Foreign Keys…

![image](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2880aa2e198f739118b7c8b14bf68ee12ae51d82.png)

And you embed a list of Device Assigns in Contract Device

![image](https://us1.discourse-cdn.com/bubble/original/3X/7/5/75bc6291f944395ae680a381ae027fe57564326d.png)

That is the One-To-Many set up. The relations are set up by maintaining the list with add/remove. if you delete the child, it is removed from the parent list - So if you don’t want to do that … put the RI constraint in code.

You navigate the relation using “appostrophe languange”.

So you you have device assign thing, you can say …

![image](https://us1.discourse-cdn.com/bubble/original/3X/8/7/87a6762ba2a4f91c1d21c557a9f85e8ec490eeea.png)

---

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [March 22, 2018, 1:30am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/7 "2018-03-22T01:30:13Z")

</div>

Thanks NigelG! I have tried Loop with “Schedule API Workflow” to loop from 1 to N then call API Workflow, can you tell me how to loop to scan a table each record from the first record to last record?  
Thanks and Regards,  
Long

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [March 22, 2018, 7:44am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/8 "2018-03-22T07:44:26Z")

</div>

Yes, “Schedule API workflow on a List”. And make that list the entire table.

---

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [March 22, 2018, 7:25pm UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/9 "2018-03-22T19:25:18Z")

</div>

Can you send me a example in Bubble, it is easy to me to understand how it works.

Regards,  
Long

---

<div class="post-metadata">

**Author:** ![lhlong](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@lhlong](https://forum.bubble.io/u/lhlong)\
**Post date:** [April 1, 2018, 7:56am UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/10 "2018-04-01T07:56:18Z")

</div>

Hi NigelG,  
Can you send me a example, I need it for my app.

Thanks!  
Long

---

<div class="post-metadata">

**Author:** ![antonio.filgueira](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@antonio.filgueira](https://forum.bubble.io/u/antonio.filgueira)\
**Post date:** [January 1, 2021, 12:20pm UTC](https://forum.bubble.io/t/do-if-then-case-do-while-loop-in-bubble-workflow/25756/11 "2021-01-01T12:20:17Z")

</div>

HI Ihlong, I have the same problem that you explain. Do you have a solution how to solve this problem. Can you help-me please.  
tks
