Help Needed: Multi-level Referral System Not Recording inv2 in Bubble

:slight_smile:Hi Bubble community,

I’m building a multi-level referral system (up to 3 levels) for my platform.
The idea is:
• When a new user signs up with a referral code, inv1 should be set to the inviter (User type reference).
• Then, inv2 should be automatically set to inv1’s inv1 (i.e., the inviter’s inviter).
• Later, inv3 will be inv2’s inv1.

Current situation:
• inv1 is being recorded correctly at signup.
• However, inv2 is not being recorded.
• I have tried:
• Direct chain expression: Current User’s inv1’s inv1 → fails if any step is empty.
• Using Set State to store ParentUser = Current User’s inv1 and then inv2 = ParentUser’s inv1 → still not working in my case.
• Tried both in front-end workflow and backend API workflow.

Data structure:
• User table:
• referral_code (text, unique)
• inv1 (User)
• inv2 (User)
• inv3 (User)
• referral_code is assigned once after signup.
• Privacy rules allow Current User to modify own inv1, inv2, inv3.

What I want to achieve:
• A reliable way to automatically write inv2 for a new user right after signup (and similarly inv3), even if there’s a delay or the inv1 was just written in the same workflow.
• Preferably a method that avoids empty value issues and works consistently.

Questions for the community:

  1. Is there a best practice for recording multi-level referral relationships in Bubble?
  2. Should I always put inv2/inv3 writing in a Backend API workflow with a scheduled delay after signup?
  3. How can I safely fetch inv1’s inv1 without breaking when there’s an empty value?

Any workflow screenshots or step-by-step examples would be super appreciated!

Thank you in advance :folded_hands:

I set up a referral system with my app.

Yours is a lot more complicated. I like to keep things simple :sweat_smile:

But, for yours to work, you have to set up a backend workflow.

thanks for your reply, i am trying build it in backend workflow.

You should not be putting this onto the User data type. You should create a new data type called ‘referral’ and have a field for the code.

I do not understand why you need to have 3 Users as inv1, inv2 and inv3. I can only assume the reason is to know which User signed up using which Referral Code. So do that, all you need to do is on the User Data Type have a field that is the Code used and can be a related field to the ‘referral’ data type I mentioned. That way you can very simply just do a search for users whose referral field is equal to a specific referral code and you can see ALL users who signed up using that referral code.

Perhaps I am making too many assumptions on your goals and needs, so if I am off base, please expand upon your use case and why you need to track inv1, inv2 and inv3.

This topic was automatically closed after 70 days. New replies are no longer allowed.