actually I have a quite simple use case.
I have a table person with name, date-of-birth, age (formula)
And i have a table “age group”, with a name and a min age. for instance:
senior 60
adult 18
teen 14
child 0
and I want a link formula in person to automatically connect the person with his current age group.
this can be done very easily in spreadsheets with the function XLOOKUP.
From here I got now some idea how to implement that with scripts:
or does any body have any idea how to achieve this without scripts?
this should not be so difficult.
Hi, many thanks for the ideas.
but both means to hard-code the values in the formula.
I want something that takes the values of the age group table.
In this simplified use case it may be even feasible to hard code the values in the formula.
In my real-life use case, that is not the case.
Here is a python script that should do the trick (don’t forget to adapt the tables’ and columns’ names even if I based the script on your screenshots):
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
# Members table's name and columns' names
members_table_name = 'Person'
members_age_group_column_name = 'Age Group'
members_age_column_name = 'Age'
# Age group table's name and columns' names
age_groups_table_name = 'Age group'
age_groups_min_limit_column_name = 'Min Age'
age_groups = base.list_rows(age_groups_table_name)
members = base.list_rows(members_table_name)
members_age_group = base.get_column_by_name(members_table_name, members_age_group_column_name);
source_ids = []
target_ids = {}
for member in members :
for age_limit in age_groups :
if member[members_age_column_name]>=age_limit[age_groups_min_limit_column_name] and len(member[members_age_group_column_name])==0 :
print(member['Name'] + " : " + age_limit['Name'])
member[members_age_group_column_name].append(age_limit['_id'])
source_ids.append(member['_id'])
target_ids[member['_id']] = [age_limit['_id']]
base.batch_update_links(members_age_group['data']['link_id'], members_table_name, age_groups_table_name, source_ids, target_ids);
As Christoph said, you can only automate the launching of the script with an automation, which needs the SeaTable Enterprise subscription, but for now you can just launch the script when you need.
I thought of something not using a script for what you need, but couldn’t find anything for now… If I figure it out, I’ll let you know.
Hi,
many thanks for the answers and in special the script.
Since the values in the referred table are quite stable,
this is indeed a good solution.
Many thanks
Michael