Passing value from a button to another form

What I’m trying to do:
I have a form where I created a data grid and one of the columns is a button that should lead to another form to show additional details of the row. I need to pass the value of the ‘action’ which would be an int.

What I’ve tried and what’s not working:
I’ve added the following code on the button

def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    open_form('Warehouse.PickingSlip', sales_order=self.item['sales_order_no'])

Code Sample:

from ._anvil_designer import ReadyToDeliverTemplate
from anvil import *
import anvil.server
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables

class ReadyToDeliver(ReadyToDeliverTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    sales_orders_data = anvil.server.call("sales_orders_ready_to_deliver")
    
    sales_orders = []
    for order in sales_orders_data:
      sales_info = {
        'sales_order_no': order['id'],
        'company_name': order['company']['identifier'],
        'action': order['id']
      }

      sales_orders.append(sales_info)

    # Any code you write here will run before the form opens.
    
    self.repeating_panel_1.items = sales_orders

Clone link:
share a copy of your app

Hi!

Have you tried creating a client side module?

A module can be imported (import statement at the top) in each of your forms and you can create variables or methods :slight_smile:

Eg if you have a module called Module1 you can create or access a variable with Module1.my_variable.

Worth noting is that is just client side, meaning all data you store in the module is just stored for each client/browser tab.

If you want to store data globally (shared with multiple clients/browser tabs) you need to use app_tables. There are several examples here in the forum :slight_smile:

Good luck :+1:

Welcome to the Forum!

Your Form class Warehouse.PickingSlip will have an __init__ function. You can add sales_order as a named parameter to that function, before **properties.

1 Like

Thank you so much, this was the solution I needed!