Iterating Document Columns and Values

Iterating Document Columns and Values
 1# This example finds a document in the active database with a specific key
 2
 3ot = impact.gui.output_toolbox
 4ot.clear()
 5
 6db = impact.active_database
 7
 8settings = db.settings.document_settings
 9
10if settings.supports_document_key:
11
12    # Display a message in the output toolbox
13    ot.add("Document storage supports document keys")
14
15    # Find the document
16    document = db.find_document_by_key(1)
17
18    # Check the document was found
19    if document is not None:
20
21        # Display the name of the document in the output toolbox
22        ot.add("Found Document Name: " + str(document.name))
23
24        values = document.values
25
26        for i in range(1, values.field_count  + 1):
27            field = values.field_name(i)
28
29            ot.add("  Field: " + str(field))
30            ot.add("    Prompt: " + str(values.field_prompt(i)))
31
32            column = document.type.columns.item(field)
33
34            val = values.load_default(field, None)
35
36            if column.multi_valued and not is_empty(val):
37                ot.add("    Multi-Valued: " + (", ").join(val))
38            else:
39                ot.add("    Value: " + str(val))
40
41    else:
42
43        # Display a message in the output toolbox
44        ot.add("Unable to find the document with key '" + str(document_key) + "'")
45
46else:
47
48    # Display a message in the output toolbox
49    ot.add("Document storage does not support document keys")