Description
Creating Document Objects
Document objects enable the management of document records. They contains data from the document record in Isah. In order to create, update or delete a document record you have to create a document object:
Dim oDocument As IPDMLink.Document
Set oDocument = New IPDMLink.Document
Managing Document Records
When you add, update or delete a document record, operations are performed on the T_DocumentMain table. This table contains a large number of fields you can retrieve and update via the document object. Before a created document record can be updated or removed, the document record has to be retrieved by a technical key and the document record data have to be read into the document object with the Refresh method.
Adding Document Records
When you add a document record with the Insert method, a technical key (DocId) will automatically be created in the database. You need this key to retrieve the document record in order to update or delete it.
The following example shows how to add a document record with a minimum of required data:
oDocument.DocCode = "NEW001"
oDocument.Description = "New document"
oDocument.Insert()
MsgBox("New document added. DocId = " & oDocument.DocId)
Retrieving the Technical Key
You can only update a document record if a technical key (DocId) for this record is available and the document record data are read into the document object with the Refresh method.
If the technical key is unknown, you can search for the document record by other properties, such as file name (T_DocumentMain.DocPathName) and revision number (T_DocumentMain.RevisionNr). You can then retrieve the technical key with an SQL statement and a query object of the Integration Server with the following code:
Dim oQuery As IERPLink.IISERPQuery
Dim lDocId As Integer
lDocId = -1
oQuery = oPDMLink.ERPLink.CreateQuery
Try
oQuery.SQL = "SELECT DocId FROM T_DocumentMain " &_
" WHERE DocPathName = 'C:\Documents\ReadMe.txt' " &_
" AND RevisionNr = 'A' "
oQuery.Open()
If oQuery.RecordCount = 1 Then
lDocId = oQuery.FieldByName("DocId").AsInteger
MsgBox("Document found. DocId = " & lDocId)
End If
Catch ex As Exception
MsgBox("Document error: " & ex.Message)
End Try
Refreshing the data
After the document record has been retrieved, you transfer the document record data to the document object with the Refresh method (amongst other things to fill the LastUpdatedOn field). As a result, all document object property values match the document record values in the database.
If the technical key is not present in the database, an error will occur if you execute the Refresh method. You can prevent undesired consequences to your application by using the try/catch statement (please refer to Deleting Document Records for an example).
Updating Document Records
In order to update a document record, it must be retrieved with the technical key and, in addition the Refresh method must have been executed. Only if these conditions have been met, you can change one or more properties with the Update method, for example the document status. However, some properties are read-only. The result of the Update method is that the document object values are written to the document record in the database.
The following example shows how you can change a document record. The Refresh method is included.
Dim oDocument As IPDMLink.Document
Set oDocument = New IPDMLink.Document
oDocument.DocId = 224538
oDocument.Refresh()
oDocument.Description = "Updated document"
oDocument.Update()
Deleting Document Records
In order to delete a document record, it must be retrieved with the technical key and, in addition the Refresh method must have been executed. Only if these conditions have been met, you can delete a record from the database with the Delete method.
The following example shows how you can delete a document record. It contains the Refresh method and a try/catch statement. If applicable, the statement shows an error message that reports that a document does not exist or that displays other errors.
Dim oDocument As IPDMLink.Document
Set oDocument = New IPDMLink.Document
oDocument.DocId = 224538
Try
oDocument.Refresh()
oDocument.Delete()
Catch ex As Exception
MsgBox "Document 224538 is not present."
End Try