Document Change Values (Python)

Document Change Values (Python)
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4ot.clear()
 5cust = db.customers.find_by_code("ACME CORP")
 6
 7if not cust.isNone():
 8    docs = cust.documents
 9
10    if docs.isNone():
11        ot.add("No customer document support in the database")
12    else:
13        ot.add("customer document support is enabled in this database")
14        doc = None
15        try:
16            doc = docs.item("Acme Corporation Specifications.docx")
17        except Exception as exc:
18            pass
19        impact.gui.output_toolbox.add(f"Failed to create object via docs.item(): {exc}")
20
21        if not doc.isNone():
22
23            ot.add("Document: '" + doc.name + "', impact.creator: " + doc.added_by.login_id + ", Size: " + doc.size + " bytes")
24            ot.add("  IsLatestVersion: " + str(doc.is_latest_version))
25
26            if doc.checkout():
27
28                ot.add("Successfully checked out document")
29                columns = doc.type.columns
30                values = doc.active_checkout.values
31
32                values.save(columns.known_item(ipDocumentKnownColumn.dkcDescription).name, "My Second Document")
33
34                ot.add("Updating active document values")
35
36                if values.do_update():
37
38                    ot.add("Successfully updated active document values")
39
40                    if doc.active_checkout.checkin(ipDocumentVersion.dvMajor, "My Checkin Comment"):
41                        ot.add("Successfully checked in document")
42                    else:
43                        ot.add("Unable to checkin document")
44
45                else:
46                    ot.add("Unable to update active document values")
47
48            else:
49                ot.add("Unable to checkout document")
50
51            for item in doc.history:
52                ot.add("  Operation: " + item.operation_as_string + " by " + item.modified_by.login_id + " at " + str(item.modified_date_time))
53                if Len(item.details) > 0:
54                    ot.add("    " + item.details)
55        else:
56            ot.add("Unable to locate document")
57
58else:
59    ot.add("Unable to locate a customer")