Skip to content
Robert S.W. Carroll edited this page Mar 17, 2022 · 1 revision

The Where() helper is one of QJAC's most helpful features. It essentially takes arguments and converts them into a QuickBase query string. Normally, a query string might look like this {3.EX.13}. This query translates to "query records with a record ID that equals 13." This is fine for simple or static queries. However, it can get a bit tedious with complex or dynamic queries. This is why Where() exists.

The Where() helper can be imported from helpers:

from quickbase_json.helpers import Where

The same query used above can be expressed by a Where() helper like so:

query_string = Where(fid=3, operator='EX', value=13).build()

Its important to either cast Where() to a string, or call the .build() method. This will get you the string representation of the Where() helper, which would look like the example mentioned above; {3.EX.13}.

Note, 'EX' is a QuickBase query operator, a full list of operators and their functions can be found here.

Used dynamically:

# get a random record from the list 13-16
x = random.choice([13, 14, 15, 16])
query_string = Where(3, 'EX', x).build()

Build Method

The .build() method of the Where() helper returns a string representation of the Where() helper. The .build() method takes one optional argument, join which expects a str.

join: str

The join argument will "join" your queries, using the value of the argument as delimiters, similar to python's .join(list) string method.

Simply put, passing 'OR' as the join argument, the query will join your value arguments.

# get a random record from the list 13-16
x = random.choice([13, 14, 15, 16])
y = random.choice([23, 24, 25, 26])
query_string = Where(3, 'EX', [x, y]).build(join='OR')

The code above would generate {3.EX.13}OR{3.EX.23} for the query_string variable. This is especially helpful if you're looking to make complex, conditional queries. Another potential argument for join is 'AND'. It could be used in the following way:

# return from quickbase records that have a status of "ON HOLD" *and* have a tracking number
# tracking no. = FID 10, status = FID 20
on_hold = 'SHIPMENT ON HOLD'
query_string = Where((10, 20), ('XEX','EX'), (,on_hold)).build(join='AND')

The important thing to note, when joining with 'AND', the Where() helper will expect tuples for all arguments.

Clone this wiki locally