This API may be used in Glom field calculations or button scripts. Field calculations have a glom_1_30.Record parameter. Button scripts have a glom_1_30.Record parameter and a glom_1_30.UI parameter.
This is the current record of the current table. A Record object is passed to field calculations and button scripts, providing access to the values of the fields in that record. The Record object passed to field calculations is read-only.
Use record[‘field_name’] to get the value of a specified field in the current record. For instance, this concatenates the values of the name_first and name_last fields in the current record.
record['name_first'] + ' ' + record['name_last']
You may also use this syntax to set the value of a field in the current record. This is possible in a button script, but not in a field calculation. For instance, this sets the value of the name_first field in the current record.
record['name_first'] = 'Bob'
How you test for empty values depends on the type of field.
Non-text fields may be empty, indicating that the user has not entered any value in the field. For instance, Glom does not assume that an empty value in a numeric field should mean 0. You can test whether a field is empty by using Python’s None. For instance.
if(record['contact_id'] == None):
return 'No Contact'
else:
return record.related['contacts']['name_full']
For text fields, you should check for zero-length strings. It is not possible in Glom to distinguish between zero-length strings and the absence of any string, because there is no advantage to doing so. For instance:
if(record['name_full'] == ''):
return 'No Name'
else:
return record['name_full']
The current database connection for use with the gi.repository.Gda API. This is a Gda.Connection object.
Related records. Use the [‘relationship_name’] notation with this object.
The name of the current table as a string.
This object provides access to related records via its [] syntax, which takes a relationship name and returns a RelatedRecord. For instance, this provides the related records for the current record, via the Record.related attribute
record.related['location']
One or more related records, returned by the [] syntax on a Related object, such as the Record.related attribute.
For relationships that specify a single record, you can get the value of a field in that record by using the [] synax, providing a field name. For instance, this is the value of the name field in the table indicated by the location relationship (often called location::name).
record.related['location']['name']
For relationships that specify multiple records, you can use the aggregate functions to get overall values. For instance, this provides the sum of all total_price values from all of the lines of the current invoice record. See the RelatedRecord class for more aggregate functions.
record.related['invoice_lines'].sum('total_price')
Count all values in the field in the related records.
Parameters: | field_name (string) – The name of the field. |
---|---|
Returns: | The summarized value. |
Maximum of all values of the field in the related records.
Parameters: | field_name (string) – The name of the field. |
---|---|
Returns: | The summarized value. |
Minimum of all values of the field in the related records.
Parameters: | field_name (string) – The name of the field. |
---|---|
Returns: | The summarized value. |
Add all values of the field in the related records.
Parameters: | field_name (string) – The name of the field. |
---|---|
Returns: | The summarized value. |
A collection of methods to programatically change the Glom UI, performing some tasks that might otherwise be done by the user via the mouse and keyboard. A UI object is passed to button scripts, allowing them to control the user interface.
Print the current layout for the current table.
Print the specified report for the current table.
Parameters: | report_name (string) – The name of the report to print. |
---|
Navigate to the specified table, showing its details view for the specified record.
Parameters: |
|
---|
Navigate to the specified table, showing its list view.
Parameters: | table_name – The name of the table to navigate to. :type table_name: string |
---|
Start a new empty record for the current table, offering the empty record in the UI.