Document UpdateFrom

Document UpdateFrom
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4ot.clear()
 5
 6cust = db.customers.find_by_code("ACME CORP")
 7
 8if cust is not None:
 9    docs = cust.documents
10
11    if docs is None:
12        ot.add("No customer document support in the database")
13    else:
14        ot.add("customer document support is enabled in this database")
15
16        doc = docs.item("Acme Corporation Specifications.docx")
17
18        if not doc.isNone():
19            ot.add("Document: '" + doc.name + "', impact.creator: " + str(doc.added_by.login_id) + ", Size: " + str(doc.size) + " bytes, version: " + str(doc.version.as_string))
20
21            latest_doc = doc.latest_version
22            ot.add("Latest document: '" + latest_doc.name + "', impact.creator: " + str(latest_doc.added_by.login_id) + ", Size: " + str(latest_doc.size) + " bytes, version: " + str(latest_doc.version.as_string))
23
24            db.errors.clear()
25
26            if latest_doc.checkout():
27                ot.add("Successfully checked out document")
28
29                active_doc = latest_doc.active_checkout
30
31                source = r"C:\\Documents\\Acme Corporation Specifications v2.docx"
32
33                if active_doc.update_from(source):
34                    ot.add("Successfully updated document from '" + str(source) + "'")
35
36                    if active_doc.checkin(ipDocumentVersion.dvMajor, "Some checkin comments"):
37                        ot.add("Successfully checked in document")
38                    else:
39                        ot.add("Unable to checkin document")
40
41                else:
42                    ot.add("Unable to update document from '" + str(source) + "'")
43
44            else:
45                ot.add("Unable to checkout document")
46
47            if db.errors.count > 0:
48                impact.gui.output_toolbox.add(db.errors.last.description)
49
50        else:
51            ot.add("Unable to locate document")
52else:
53    ot.add("Unable to locate a customer")
54
55