New Bug Encountered: Foreign key not populated when ref row is added

Hello,

I have created a simple app that has a โ€œMealsโ€ table in Google Sheets and an โ€œAdditionsโ€ table in a second tab in the same sheet. The โ€œAdditionsโ€ table has its own Key column which is initialized with UNIQUEID() and a โ€œMealโ€ Ref column that refers to the โ€œMealsโ€ table. Note that the โ€œMealโ€ Ref column is not shown.

When using the unpublished app, when I use the โ€œAddโ€ link to add a new โ€œAdditionโ€ to a โ€œMealโ€, more often than not, the new โ€œAdditionโ€ appears in the list of referenced rows, but when I press the sync button, the row vanishes. Looking at the data, the โ€œMealโ€ column is not populated.

Any ideas why this may be happening and how to fix it?

Thanks

Miles

0 13 288
13 REPLIES 13

Derek3
New Member

Hi Miles,

Do you have โ€œis a part ofโ€ turned on for the โ€œMealโ€ Ref column in the โ€œAdditionsโ€ table?

When you turn โ€œis a part ofโ€ on, it allows you to add new line items to that table (โ€œAdditionsโ€ table in this case) while completing the referenced form (โ€œMealsโ€ table in this case).

From inside the form view for โ€œMealsโ€, when you click โ€œAddโ€, it will bring you to the form view for the โ€œAdditionsโ€ table. After completing the โ€œAdditionsโ€ form, you click โ€œSaveโ€ and it brings you back to the โ€œMealsโ€ form. From there, you can click โ€œAddโ€ again or continue with the rest of the form. At the end of the โ€œMealsโ€ form, you click โ€œSaveโ€ and the changes will sync back to the data source.

Important: The items you add to the โ€œAdditionsโ€ table will not be synced back to the data source until you click โ€œSaveโ€ on the parent tableโ€™s form (โ€œMealsโ€ in this case).

So my first guess is that you may be pressing the sync button before completing the โ€œMealsโ€ form.

Another good thing to check is the referenced table for your โ€œMealsโ€ Ref column.
*Go to Data > Columns and click to expand the โ€œAdditionsโ€ table.
*Click the edit pencil next to the โ€œMealsโ€ column
*Check that โ€œSource tableโ€ is set to โ€œMealsโ€

Cheers,
Derek

Hi Derek,

Thanks for the prompt suggestions.

Populating the โ€œMealโ€ column in the โ€œAdditionsโ€ table used to work, but it does not seem to work now. I have now enabled the โ€œis a part ofโ€ setting for the โ€œAdditionsโ€ table and confirmed that the โ€œMealโ€ Ref column has its source set to โ€œMealโ€, but this still does not seem to work.

Might it matter that I have manually edited the sheetโ€™s data (i.e. does AppSheet try and remember state about the underlying spreadsheet and it may be getting confused)?

Miles

Unlikely.

Please post screenshots of the column lists (from Data >> Columns in the app editor) for the two tables. Letโ€™s start there.

Attached are some images for you to look at.
As I am a new user this will take three postsโ€ฆ
Might it make sense to share the app with you and Derek?

Meals columns:

Additions columns:

Meal Ref column details:

How are you adding an Additions row when it doesnโ€™t work as expected?

Yes. Using the โ€œAddโ€ link under โ€œRelated Additionsโ€. The sequence is:

  1. Select a Meal
  2. Click the โ€œAddโ€ link.
  3. Specify a name for the Addition and press โ€œSaveโ€. This returns me to the Meal.
  4. The Addition shows up in the list of โ€œRelated Additionsโ€, but not in the Google Sheet.
  5. Press the sync (top right) button.
  6. When the Meal refreshes, the new entry is not in the โ€œRelated Additionsโ€ list, but there is a row in the spreadsheet, but its Meal value is not populated.

An additional possibly important point:
The โ€œMealโ€ sheet is in the same Google Sheet as the โ€œAdditionsโ€ sheet, but a different tab.

Please post a screenshot of the complete App formula expression for the Related Additions column.

Thatโ€™s typical. Not a problem.

App formula expression for the Related Additions column:

That looks correct.

Is there a Spreadsheet formula configured for the Meal column in the Additions table?

Is Editable? set to ON for the Meal column in the Additions table?

Have you added any actions (via Behavior >> Actions) to your app? Or made changes to any of the system-generated actions?

Do you have any workflows (Behavior >> Workflows) or reports (Behavior >> Reports)?

There is no โ€œformulaโ€ values for any field in the โ€œAdditionsโ€ table.
The โ€œKeyโ€ column has an initial value formula of UNIQUEID().

Ah ha! That was it. I set Editable? to ON and it started working!
I probably turned this off at some point, because I did not want an โ€œAdditionโ€ to move between โ€œMealsโ€ (before I set Is a part of? to ON).

None added.

None added.

Thanks for all of your help Steve.

How would a developer identify this issue without this kind of support?

Miles

Derek3
New Member

Iโ€™m glad you were able to find the culprit. Steve is in fact an AppSheet Jedi!

There is a team of people whose goal is to make the AppSheet learning curve as easy as possible, but sometimes youโ€™ll find things like this that take some experimentation.

Everyone has their favorite resource. I always like to start from a working example of something similar. For that, there is a collection of free sample apps you can copy to your account. Iโ€™ll often compare what Iโ€™m working on to the sample app and try to find the differences. And of course your community is here as resource as well.

Top Labels in this Space