Not assigning relationship to user from secondary table

Hi there,

Summary: User table not correctly linked to another table and therefore users are not assigned to the other data items

I have 2 tables.

  1. Users (containing email, password, and company)
  2. Companies (email domain, users)

The relationships between Users and Companies is that each company can have many users, but each user can only have one company. The company name is the users’ email domain (which is collected by parsing the email through a function in Xano - this is the custom action EmailDomain). The email domain is then returned.

I am not currently able to collect the user when I collect the email domain (the result of the custom action EmailDomain).

Here is a video summarizing the issue I am currently facing:

Any advice how to handle this is much appreciated!

Sam

Hey @Sam2

For starters, from your video, your relationship between companies and users is a “many to many” (I can tell by the icons).

So when you create a new “company” when the relationship is “many-to-many,” you can add another action below the create action as an “Update > New Company” action which will show the Users parameter where you can then “Add > Logged in user”:

Now if you switch the relationship to a one-to-many relationship where user can only have 1 company but company can have multiple users, you can simply add this parameter on an update logged-in user action after the company create action, like this:

2 Likes

Hey @Flawless!

Many-to-many relationship
Thanks for that spot - I was playing around and didn’t switch it back to one-to-many (doh).

Linking user solution
The rest of your detailed description worked a charm.

Grouping company users
What is the simplest way you would suggest of adjusting the above slightly to add the logic:

IF a user’s emaildomain (i.e. company), already exists THEN update the company to add the user.

IF a user’s emaildomain (i.e. company), does not already exist THEN create a new company and assign the user to it .

The solution I currently have (thanks to your help) will always create a new company.

I provide a little more detail to the problem I am looking to solve in this Loom.

Thanks again! Much appreciated,

Sam

This is a lot more advanced and not possible without the aid of an API.

However, this is possible if you know how to use custom actions. Here’s documentation on that if you need help: https://help.adalo.com/integrations/custom-actions

@Abracadalo has an API called “String API” that you can use: https://docs.abracadalo.com/string-api#split Note: this does require having a FREE account with Abracadalo. Their string API is free to use, but some of the other APIs require the paid subscription. Just FYI.

Here’s how:
First, add a new text parameter to the user collection and call it “email domain” and add a text parameter to the company collection and call it “company domain”.

You don’t want to perform too many actions on 1 page, so let’s simplify the actions and make 2 screens.

The first screen will sign up the user. Email and password.

Add a custom action below the “Sign up” action using the string API with the “split” feature using the @ as the separator.

You can use the result of this API call to update the user’s “domain” parameter. So below the custom action, add an update logged-in user action to fill in the user domain.

Then, link to the next screen. Call the next screen “Loading” and delete all components. You can add a loading image or a lottie file animation for the user to see that actions are happening in the background.

Add 2 countdown timers to the screen and set them both to 3 seconds each.

Countdown timer 1, set the visibility to “Sometimes” if “Company > Count > is equal to > 0” with a custom filter where “company domain > is equal to > logged in user > domain”. Set the action to Create a company. Be sure to use logged-in user > domain to update the company domain parameter and then link to your preferred next screen.

Countdown timer 2, make a list from the countdown by clicking the settings button when the countdown is selected and click “Make a list”. Set the list to “Companies > All Companies”. Add a custom filter where “Company domain > is equal to > logged in user > domain”. Set the action to update company and add the logged-in user. Then link to your preferred next screen.

1 Like

Thank you for such a detailed solution @Flawless. Really appreciate it and looking forward to implementing it!

Out of interest what is the reasoning behind the 3 seconds?

Happy to help :gem:

I’ve noticed that 1-second countdown timers sometimes still execute their actions if it hasn’t fully loaded the visibility settings. I choose not to take the same chance 2-seconds. 3 seconds works like a charm (in most cases) and isn’t terribly long for the user (since this will only happen once when the user is first signing up anyways).

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.