How do I assign one Thing to another?

Hi,

In our database User has a field called “Plan” which is another object in bubble. However after assigning the Plan to the User as below, the plan field of the user is still empty. Any ideas?

plan = Search for Plans:first item

Basically Search for plans searches the plan by Id and can confirm that it is found, however the assignment of it to the User’s plan field fails.

Is this not the way to assign things to each other? Here there is a one to many relationship, where every user has a Plan

Thanks

Hi there, @saasbox… does the debugger give you any clues as to why the assignment is failing? Are you sure a plan is being returned in the search? Do you have any privacy rules in place on the Plan or User data types that could be getting in the way?

Best…
Mike

Thanks for the reply @mikeloc. I checked and there are no privacy restrictions, debugger evaluates the right side to a valid plan. Is that the right way to assign a thing as a field on another thing? Next I am going to try a simpler assignment to see if that works.

Hey, @saasbox,

Are you creating the plan and then assigning it to the user in the same workflow?

Well, it’s the right way if it assigns the appropriate plan to the current user, so in this case, no, it’s not the right way. :slight_smile:

Kidding aside, if the plan field on the User data type is linked to the Plan data type, and if the search evaluates to a valid plan, then it should work in theory. What is the constraint on the search?

Yes, create plan if it does not exist, then assign to user in the next workflow step. Is that a problem to do it in the same workflow?

Perfect. So, you sign the user up, set fields, create a new plan (if it does not exist) and want to assign that user the plan that was just created, right?

If yes, you can do the following

In the Assign Plan to User action you do:
Plan = Result of Step 4's Plan

And that’s it

I don’t think that’s going to work because I assume step 4 is a custom event, and to the best of my knowledge, you can’t reference the result of a custom event. So, @saasbox, you might try adding a step to the custom event that assigns the newly-created plan to the user only when the result of the step that creates the plan is not empty. Then, change step 5 to search for the appropriate plan to assign to the user only when the user’s plan is empty (which it will be if the custom event finishes without creating a new plan and assigning it to the user).

The issue with this is Step 4 creates the plan only if it doesn’t exist, so the result of Step 4 is not always a plan. Step 5 re-queries the plan to assign it.

Thanks to both of you for the help.

Querying the plan is done as shown. In the debugger evaluating by clicking on “first item” does show the plan, but somehow assignment doesn’t work. (no errors seen)

How does an assigned object look like in the User object’s related field in the database, since it is a whole object? Is it shown by its unique id?

I will try something simpler to verify that object assignment like this works.

Yes, that is how it’s shown by default (you have that ability to change it to something other than the unique id, though).

So, if it’s a custom event.

You can do this action in the CE (custom event)

The issue was the Search for Plans query. SaaSBoxId is a UUID saved as text in the database:
uuid-as-text

The same field “user plan id” is used to save the value for SaaSBoxId when creating the plan in the previous step. Unfortunately querying the same value right after (as I shared in the earlier message) does not work.

What worked was querying it by the name field as here:

The only difference seems to be the SaaSBoxId field has hyphens ‘-’ in them. Not sure why it doesn’t work.

This is an issue because the uuid is a reliable way to uniquely identify the data/thing instance.