How can I automatically update the dropdown content (values) in Smartsheet column (set with dropdown property). I would like the dropdown content in my target Smartsheet updated based on the values inputted on a separate Smartsheet (Source Smartsheet).
Using smartsheet-python-sdk, i tried implementing the following code with no noticeable updates to the dropdown in the target sheet…
import smartsheet
# Initialize client
access_token = 'XXXXXXXXXX'
smartsheet_client = smartsheet.Smartsheet(access_token)
# IDs of the source and target sheets
source_sheet_id = 'XXXXXXXXXX'
target_sheet_id = 'XXXXXXXXXX'
source_column_id = 'XXXXXXXXXX'
dropdown_column_id = 'XXXXXXXXXX'
# Defining this function to get unique values from the source sheet column
def get_unique_values(sheet_id, column_id):
sheet = smartsheet_client.Sheets.get_sheet(sheet_id)
values = set()
for row in sheet.rows:
for cell in row.cells:
if cell.column_id == column_id and cell.value:
values.add(cell.value)
return list(values)
# Getting unique values from the source sheet
dropdown_values = get_unique_values(source_sheet_id, source_column_id)
# Updating the dropdown column in the target sheet
column = smartsheet_client.Sheets.get_column(target_sheet_id, dropdown_column_id)
column.options = dropdown_values
updated_column = smartsheet_client.Sheets.update_column(target_sheet_id, dropdown_column_id, column)
# Visualizing the updates
print(f"Updated dropdown values: {updated_column.options}")