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_key = 1
17 document = db.find_document_by_key(document_key)
18
19 # Check the document was found
20 if not document.isNone():
21
22 # Display the name of the document in the output toolbox
23 ot.add("Found Document Name: " + str(document.name))
24
25 values = document.values
26
27 for i in range(1, values.field_count + 1):
28 field = values.field_name(i)
29
30 ot.add(" Field: " + str(field))
31 ot.add(" Prompt: " + str(values.field_prompt(i)))
32
33 column = document.type.columns.item(field)
34
35 val = values.load_default(field, None)
36
37 if column.multi_valued and not (val is None or val == ""):
38 ot.add(" Multi-Valued: " + str((", ").join(val)))
39 else:
40 ot.add(" Value: " + str(val))
41
42 else:
43
44 # Display a message in the output toolbox
45 ot.add("Unable to find the document with key '" + str(document_key) + "'")
46
47else:
48
49 # Display a message in the output toolbox
50 ot.add("Document storage does not support document keys")