0

Retrieving the list of possible values in a field?

We have a field which was defined as a drop-down list. Is it possible to query Shotgun and retrieve the list of allowed values?

4 comments

  • 0
    Avatar
    Nephi Sanchez

    Hi Mihail,

     

    Yes!  I'm assuming you are using the Python API, is that correct?  If so, you can use the schema_field_read() method.  

     

    Here's an example of the syntax to find what are valid values for the 'sg_type' field on Tickets:

     

     

    s = sg.schema_field_read('Ticket', 'sg_type')
    print s['sg_type']['properties']['valid_values']['value']

    s = sg.schema_field_read('Ticket', 'sg_type')

    print s['sg_type']['properties']['valid_values']['value']

     

    This returns a list object that looks something like this:

    ['Bug', 'Deploy', 'Design', 'Documentation', 'Consistency', 'Enquiry', 'Feature', 'Finance', 'Infrastructure', 'Marketing', 'Meeting', 'Migration', 'Optimization', 'Planning', 'Polish', 'Refactoring', 'Sales', 'Spike', 'Street', 'Support', 'Testing']

    ---

    Check out our documentation post here:

    https://support.shotgunsoftware.com/entries/21668-reference-methods#schema_field_read

     

    And if you are just getting started with the API, check out this section:

    https://support.shotgunsoftware.com/forums/48807-developer-api-info

    ---

     

    Cheers,

    Nephi

     

  • 0
    Avatar
    Mihail Temelkov

    Thanks, Nephi.

    I did try sg.schema_field_read(), but I can't get past 'properties', because the 'valid_values' dict is missing.

    >>> s = sg.schema_field_read('Version', field_name='description')
    {'description': {'mandatory': {'editable': False, 'value': False}, 'description': {'editable': True, 'value': ''}, 'data_type': {'editable': False, 'value': 'text'}, 'entity_type': {'editable': False, 'value': 'Version'}, 'editable': {'editable': False, 'value': True}, 'properties': {'default_value': {'editable': False, 'value': None}, 'summary_default': {'editable': True, 'value': 'none'}}, 'name': {'editable': True, 'value': 'Description'}}}

    >>>s['description']['properties']['valid_values']['value']
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'valid_values'

    >>>s['description']['properties']
    {'default_value': {'editable': False, 'value': None}, 'summary_default': {'editable': True, 'value': 'none'}}

     

  • 0
    Avatar
    Nephi Sanchez

    Hi Mihail,

    That field is of type 'text', so it doesn't have that property:  See the 'data_type' - it has a value of 'text'.  On fields that have a 'data_type' of 'list', you'll get the expected dictionary of valid values.

     

    If you are curious and want to see the schema of all the fields for Version, just leave out that second argument:

    s = sg.schema_field_read('Version')

    And it will return the schemas for all the fields, if you want to study them.

     

    - Nephi

  • 0
    Avatar
    Mihail Temelkov

    Thanks, Nephi. I'll ask our Shotgun admin to change the field type.

    I've been using schema_field_read for a while now, and wrote some utility functions that leverage it.

     

    Cheers.

Please sign in to leave a comment.