Problem defining relationships between tables

Hello,

I’ve completed the mission where we define the relationships between tables, and think I understand the logic behind it, but I am having trouble making it work in a different situation.

In the mission, you use a value from page data to set the relationship. In my case, I want to set the relationship using a fixed value from the other table.

So I have a table called TaxYears which has a column called taxYearEnding:

I also have a table called UserTaxYears, which has a column called yearEnding which has 1-2-1 data object relationship with TaxYears.

The relationship is linked to the column taxYearEnding

When a user creates an account, I want to also create a record in the UserTaxYears table, and create a relationship to the TaxYears table, to set the yearEnding column in UserTaxYears to link to the 2022 value in the taxYearEnding column in the TaxYears table.

I start by creating a new user, and returning the object as a variable newUser in page data. I then set a variable in page data called ownerId with the ownerId from the newUser variable:

I then create a new record in the UserTaxYears table, passing the variable ownerId into the ownerId column of the userTaxYears table. I then return this new record as a property in page data called newRecorduserTaxYears:

Then I create a variable called taxYear which is the 2022 value from the taxYearEnding column of the TaxYears table:

Finally, I attempt to set the object relations and then take the user to the login page:

When I test this, it fails to take the user to the login page, the network tab shows the following:

The record is created in the UserTaxYears table but the data relationship does not exist:

I suspect I may have overcomplicated this! So if there’s an easier way to do it, I’d be very happy to hear it.

I’ve tried a lot of different things to get it to work, but have not been able to do so. Any help much appreciated!

Hi Luc,

When you retrieve data from TaxYears you already get a collection of objects since Load Table Objects always returns a list (even if you set page size to 1):

As a result, creating a new list from the taxYear variable is not needed (and that’s what messes up when a relationship is created):

Hope this helps.

Regards,
Mark

@mark-piller

I’ve made that change:

But it is still not setting the relationship in the table or progressing to the userLoginPage

Hello @Luc_Zentar

make sure your input values are correct, you can check them by adding a “Print” block and to see the result in the Browser Dev Tool

progressing to the userLoginPage

do you mean it doesn’t redirect to the userLoginPage ? can you see any errors in the Browser Dev Tool?

@vladimir-upirov I’m not sure what you mean by adding a print block. There is no error in the network console:

It seems to be failing at the set object relations stage, the relation is not set and the Go To Page logic is not executed.

you can print anything with this block to debug intermediate values.

I do not see any errors (except favicon) on the screenshot you shared

@vladimir-upirov thank you, I have added the print block and have done my best to debug in my browser dev tool, but I’m still stuck. Like you, I can’t see any errors in the dev tool, but the blocks are still not working.

The network tab seems to show that the block that sets the variable taxYear is working. After that it should set the object relations and then take the user to the page userLogin. But the object relations are not set and the user is not taken to the userLogin page.

The network tab doesn’t show anything else happening after the find response that returns the correct value for the variable taxYear.

Hello @Luc_Zentar,

To set the relation, the both parent object and children should exist (should have the objectId property). Please make sure the newRecordUserTaxYears object has the objectId and add the objectId to properties when loading taxYear (according to the screenshot the tax year object doesn’t have the objectId right now):

Regards,
Olha

Thanks guys!