Hi, I’ve just started using Grist, and am amazed at how this is such a hyper-powered variant of any online spreadsheet tool out there!
I am configuring a column in a table (table A) to be a reference list and trying to extract a list of item names from another table (table B) that matches a mathematical condition (weight should be less than or equal to) dependent on a field in table A (max allowed weight).
If I set a fixed value, & use only the equals (=) operator, then it seems to be ok, but if I set it to be a variable and set less than or equal (<=) operator, it throws a #NameError and claims that the field (weight) is not defined. What am I doing wrong?
Also note that in Python = is an assignment and == is an equality. My guess is that the = version works without apparent error because you’re assigning the value instead of comparing it.
Do you have an example of the code you’re trying to write here?
Maybe try this:
in table A, turn the reference list column into a formula:
# Make a list to hold our records from B that match the condition.
result = []
# Get all records from B.
all_records_from_B = B.all
# Iterate over these records...
for record_from_B in all_records_from_B:
# ... and check each against the 'weight' column on this (A) table.
if record_from_B.weight <= $weight:
# If the condition is met, add the record to our results list.
result.append(record_from_B)
# Finally, return the results to populate the reference list column.
return result
Is this what you’re looking for? If indeed it is, you might opt for a more concise version:
# Use Grist's builtin 'find.le' (lower-or-equal) method to return only matching records from B.
return B.lookupRecords().find.le($weight)