I have a form displaying customer details from the database. One of those columns is orders which is a linked column to the orders data table. The orders are listed as links in the customer form. When each link is clicked i want to open a form displaying all the information about that order. How can I pass that orders row id to the display form template so i can fetch that record from the database?
A simple example app to demonstrate your setup would make it easier to give better assistance; however, this is what comes to mind (let’s assume your’re using the Material Design):
When you open a form, you can pass variables along that are accessible in the init
of the opened form. For example,
```python
# in Form1
from Form2 import Form2
.
.
.
my_new_form=Form2(details=my_details)
self.content_panel.clear()
self.content_panel.add_component(my_new_form)
```
Then, in the init
of Form2, you can access the variable my_details
with properties['details']
I think there are variations to this but hopefully this gets you started. You may also search the forum for “tag” and “session data” as these are also ways to store data for later use.
Good luck and feel free to clarify with a small example app and code.
thanks for the help, I wanted the new form to be triggered by a link element. this is the code that worked for me.
1) In a server module i have defined a function:
@anvil.server.callable
def get_one_project(project_id):
project = app_tables.projects.get_by_id(project_id)
return project
2) In the initiating form:
from Project_Details_Template import Project_Details_Template
.
.
.
def subcontractor_project_click(self, **event_args):
“”“This method is called when the project link is clicked”""
open_form(Project_Details_Template(project = self.item.get_id()))
3) In the init method of the form being opened by the link click event:
self.item = anvil.server.call(‘get_one_project’, properties[‘project’])
Thanks again
Glad you got it working. You can format your code so that it is easier to read on the forum by following these instructions.
Your point 3 can also be done like this:
class MyForm(MyFormTemplate):
def __init__(self, project, **properties):
self.init_components(**properties)
self.address_dict = anvil.server.call('get_one_project', project)