Only allow updates by Context("Table")?

I have a form for my “Stock In” table, that has a reference to my “Medication” table.
I only want to allow users to add a row to the Medication table using the Medication form.
When a user adds a new “Stock In” item via the form, the Medication field is a modal that lists the Medications as well as a “New” option. I want to disable the “New” option from the “Stock In” form.
I’ve tried adding a switch to the “Are updates allowed?” expression of the Medication table, like so

SWITCH(CONTEXT("Table"), 
  "Medication", "ADDS_ONLY", 
  "READ_ONLY")

Seems like that should work wonderfully but that hides the + button on the Medication primary view.
Why doesn’t that work?
I’ve also tried switching on Context(“View”) but no luck there either. It displays the + button on the Medication view but then when I click it I get an error “Table Medication does not allow new entries” because the view has changed to be the form (which I noticed doesn’t have a View param in the URL).
Any other ideas for disabling additions from the reference modal?

Solved Solved
0 2 212
1 ACCEPTED SOLUTION

Aurelien
Google Developer Expert
Google Developer Expert

Hi @CMA-Admin

Welcome to the community !

I think you have the “New” option because your field refers to the table, which allows adds.
It probably looks like this in the Data/Table panel (please replace Products with Medication in your case):

To avoid this, you have to create a slice with ReadOnly options.
That will work like an identical twin of your Medication table, but with no change allowed.

To do so:

  • create a new slice that I suggest you call Medication_ReadOnly, and check these informations (remember to substitute Products with Medication from my example):

  • on your “Stock In” table, click on the black pen:
    3X_e_e_ee0422023257f564d4dc95846c6fa429b68f1148.png

  • then, change your Source table, from Medication to Medication_ReadOnly
    3X_6_b_6bcd2a638e0675f58f6087f343f0979c52919601.png

Let us know if that works for you !

View solution in original post

2 REPLIES 2

Aurelien
Google Developer Expert
Google Developer Expert

Hi @CMA-Admin

Welcome to the community !

I think you have the “New” option because your field refers to the table, which allows adds.
It probably looks like this in the Data/Table panel (please replace Products with Medication in your case):

To avoid this, you have to create a slice with ReadOnly options.
That will work like an identical twin of your Medication table, but with no change allowed.

To do so:

  • create a new slice that I suggest you call Medication_ReadOnly, and check these informations (remember to substitute Products with Medication from my example):

  • on your “Stock In” table, click on the black pen:
    3X_e_e_ee0422023257f564d4dc95846c6fa429b68f1148.png

  • then, change your Source table, from Medication to Medication_ReadOnly
    3X_6_b_6bcd2a638e0675f58f6087f343f0979c52919601.png

Let us know if that works for you !

Great alternative! That makes sense. I will try this when working on it tonight.
That’s a great approach in general for creating read-only lists from tables. I’ll add that to my quiver of tricks.

Top Labels in this Space