Creating Document Relationships

Creating Document Relationships
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4ot.clear()
 5
 6docs = db.documents
 7
 8if docs is None:
 9    ot.add("No document support in the database")
10elif db.settings.other_documents:
11    ot.add("Other document support is enabled in this database")
12
13    doc = docs.add(r"C:\\Documents\\ExampleDocument1.docx", "My First Document")
14
15    if not doc.isNone():
16        ot.add("Document '" + doc.name + "' successfully created")
17
18        if not doc.database_item.isNone():
19            ot.add("ERROR: DatabaseItem should not be set")
20
21        if not doc.customer.isNone():
22            ot.add("ERROR: customer should not be set")
23
24        ot.add("Added: " + str(doc.added_date_time) + " by " + str(doc.added_by.login_id))
25        ot.add("version: " + str(doc.version.as_string))
26        ot.add("Size: " + str(doc.size) + " bytes")
27
28        r1 = doc.relationships
29
30        ot.add("Relationship Count (Before): " + str(r1.count))
31
32        # create a relationship to a user by U_LOG_NAME or U_KEY
33        r1.add(ipDocumentRelationship.drUser, "", "FRED", "")
34        r1.add(ipDocumentRelationship.drUser, "", 6, "")
35
36        # create a relationship to a project by D_KEY, D_CODENUM or D_GUID
37        r1.add(ipDocumentRelationship.drProject, "", 61200, "")
38
39        # r1.add() ipDocumentRelationship.drProject, "", "P061100", ""
40        # r1.add() ipDocumentRelationship.drProject, "", "15e49dd1-b8b2-4aa5-892b-c8cd47a43a5c", ""
41
42        # create a relationship to a site by ST_KEY or ST_NAME
43        r1.add(ipDocumentRelationship.drSite, "", 5, "")
44        r1.add(ipDocumentRelationship.drSite, "", "ANDROMEDA", "")
45
46        # create a relationship to a customer by CS_KEY or CS_CODE
47        r1.add(ipDocumentRelationship.drCustomer, "", 1, "")
48        r1.add(ipDocumentRelationship.drCustomer, "", "ACME CORP", "")
49
50        # create a relationship to another document by Key (if supported) or ID
51        r1.add(ipDocumentRelationship.drDocument, "", 10, "")
52
53        # r1.add() ipDocumentRelationship.drDocument, "", "6b9a0a91-6f97-4321-8957-fce1e7cc59b5", ""
54
55        # create a relationship to an external type storing an object reference by varchar(50)
56        r1.add(ipDocumentRelationship.drExternal, "webcnx:task", "1234567890", "")
57
58        # set r2 = doc.relationships
59        r2 = r1
60
61        ot.add("Relationship Count (After): " + str(r2.count))
62
63        for r in r2:
64            ot.add("Relationship: " + str(r.relationship_as_string))
65
66            if r.relationship == ipDocumentRelationship.drExternal:
67                ot.add("  ExternalType: " + str(r.external_type))
68
69            ot.add("  Document: " + str(r.document.id))
70            ot.add("  CreatedBy: " + str(r.created_by.login_id))
71            ot.add("  Created: " + str(r.created_date_time))
72            ot.add("  ObjectID: " + str(r.object_id))
73            ot.add("  version: " + str(r.version))
74
75    else:
76        ot.add("Unable to create new document")
77
78