Hi Shaoying, welcome to the Forum!
In short, there’s a Data Binding somewhere that you can probably just delete, but here’s a longer explanation!
The problem
The problem is not in the main code, but in a Data Binding. The error message says that it’s in ‘a data binding for self.text_box_1’:
anvil.server.InternalError:
Permission denied: Cannot write in table ‘Grades’ from client code.
while setting self.item[‘score’] = self.text_box_1.text
in a data binding for self.text_box_1
Somewhere in your app, there’s a TextBox called self.text_box_1
with a Data Binding like this:
(This Data Bindings panel can be found in the Propoerties pane when you select the TextBox.)
I expect you have a Form called ItemTemplate1
, which is the template of a RepeatingPanel. In that case, I guess the RepeatingPanel’s items
is set like this (probably in Form1):
self.repeating_panel_1.items = app_tables.grades.search()
So inside the ItemTemplate Form, self.item
is a row from the grades
table.
The error comes because the Data Binding has the Write back
box checked. That means it will try to write self.text_box_1.text
into self.item['score']
, and because self.item
is a Row from the grades
table, it does not have permission to do this.
How to fix it
The easiest way
The easiest way is to make the grades table client-writable. Go to the Data Tables Service and select ‘Can search, edit and delete’ for the grades table:
The most secure way
This is not ideal in terms of security though - anybody who uses your app can manipulate the code in their browser to read and write to the grades table however they want.
The more secure way is to remove the Data Binding. You can get the same result by writing a function in a Server Module write to the grades table, then call it from the change
event of text_box_1
. That way, the grades table can still be ‘No access’ from the client, and your server function controls what gets written to it.
It sounds like that’s what you’re trying to do - you want to call num_to_grade
from text_box_1_change
, so the Data Binding is no longer required.