Useful Snippets
Welcome to our collection of useful code snippets for QReserve's scripting language, sneq. This page contains practical examples that demonstrate common patterns and techniques you can apply in your own scripts. Whether you're creating dynamic rates, customizing invoices, or automating workflows, these snippets will help you leverage the full power of QReserve's scripting capabilities. Feel free to copy, modify, and incorporate these examples into your own implementation.
Find A Form Field Value From ID
This script allows a user to use a Custom ID to find specific field values. This could be use to gather values to be used in other blocks of code to change how something behaves based on submitted information.
To use it, the custom_id variable must be set to the custom ID.
FORM_ID = 'zy6cs3whopcvedal105biwa8fd4q16i8q98h9'
CUSTOM_ID = 'my_custom_form_id'
form_response = util.forms.form_response_from_form_id(
form_id=FORM_ID)
# All form options without custom IDs will default to the string 'None'.
# 'model' is the internal ID for a form schema.
custom_id_to_model_id = {
str(util.dicts.get(d=row, path='customId')): util.dicts.get(d=row, path='model')
for _, row in form_response['schema']
}
value_for_custom_id = util.forms.form_response_value_from_form_id_and_field_id(
form_id=FORM_ID,
field_id=util.dicts.get(d=custom_id_to_model_id, path=CUSTOM_ID)
)