Home
TeamSite
Using VBA to control folder content
System
Using iManage type 8.0 library and Worksite 8, I am trying to update a working import function, to import a local document to Worksite and then add a reference to the document in a selected workspace folder.
Here's the code at the moment (a little para-phrased).
Dim fldrContents As IManage.IManDocuments
Dim CheckedinDocument as IManage.IManDocument
Set CheckedinDocument = NewDocument.CheckInEx(TempPath & strTempFile, nrReplaceOriginal, nrDontKeepCheckedOut, nrHistoryCheckin, "LAWSOFT", "Generated from CC Chains", "", ErrResults)
'check into new document instance the locally stored document - temppath is a constant and strtempfile the name of the locally saved file.
Set fldrContents = FindFolder.oSaveFolder.Contents
'find folder is an external addin which identifies the folder ID of the folder the content should save to...
Set CheckedinDocument = fldrContents.AddDocumentReference(CheckedinDocument)
'This line "should" I think copy a reference to the current imported document into the selected folder.
However the final line of code generates this error each time the code runs:
[DocumentContents][AddDocumentReference ]The parameter is incorrect?
Can anyone shed any light on this error or how to move document references between/ into folders through VBA?
Find more posts tagged with
Comments
jny
Use the ImportCmd to automate this series of tasks. Like so:
[VB]
Dim context As IMANEXTLib.ContextItems
Dim cmd As IMANEXTLib.ImportCmd
Dim dms As New ManDMS
Dim sess As IManSession
Dim db As IManDatabase
Dim docFolder As IManDocumentFolder
Dim newDoc As IManDocument
Dim dblist As New ManStrings
Dim params As IManFolderSearchParameters
Dim searchResults As IManFolders
Dim sPath As String
Dim i As Long
On Error GoTo ERROR_HANDLER
' Put in your own login values
Const SERVER = "WS-RED"
Const DATABASENAME = "WDIMAN80"
Const USER = "JYEE"
Const PASSWORD = "MHDOCS"
' Login
Set sess = dms.Sessions.Add(SERVER)
' sess.Login USER, PASSWORD
sess.TrustedLogin
sPath = "C:\Temp\Dummy Dox\My test file.doc" 'Arbitrary example of a filepath to the import file.
' Get database
Set db = sess.Databases.ItemByName(DATABASENAME)
'Build a list databases in which to search
dblist.Add db.Name 'Example of searching under one database
'Build folder search criteria
Set params = dms.CreateFolderSearchParameters
' Arbitrary example of search values by which to search
params.Add imFolderName, "DOC" 'Arbitrary example of a folder name by which to search
params.Add imFolderOwner, sess.UserID 'Assuming the folder belongs to the currently logged-on user
'Search for target folder
Set searchResults = sess.WorkArea.SearchFolders(dblist, params)
'Check search results
If searchResults.Empty Then
MsgBox "Folder not found."
GoTo Cleanup
End If
Set docFolder = searchResults.ItemByIndex(1) 'Assuming the target folder is the first item in the collection
Set context = New IMANEXTLib.ContextItems
With context
' The WorkSite object you pass in can be _
a database, session, or folder. Depends on _
at where you want the imported doc to be stored.
.Add "IManDestinationObject", docFolder 'sess.PreferredDatabase
' Filename set here is used for easy example, _
a string variable is normally used here
.Add "IManExt.Import.FileName", sPath
.Add "IManExt.Import.DocAuthor", sess.UserID
' Optional values
.Add "IManExt.NewProfile.ProfileNoUI", True ' Skip UI
' .Add "IManExt.Import.DocDescription", "preset desc"
End With
Set cmd = New IMANEXTLib.ImportCmd
cmd.Initialize context
cmd.Update
If cmd.Status = (cmd.Status And nrActiveCommand) Then
cmd.Execute
End If
On Error Resume Next
Set newDoc = context.Item("ImportedDocument")
context.Remove "ImportedDocument"
If Not newDoc Is Nothing Then
MsgBox "Imported document number: " & newDoc.Number & "_" & newDoc.Version
End If
GoTo Cleanup
ERROR_HANDLER:
MsgBox Err.Description
Err.Clear
Cleanup:
' Logout and close app
If sess.Connected Then sess.Logout
dms.Close
' Free memory
Set context = Nothing
Set cmd = Nothing
Set newDoc = Nothing
Set db = Nothing
Set docFolder = Nothing
Set dms = Nothing
Set sess = Nothing
Migrateduser
Many Thanks jny, I should be able to try this code this afternoon/ tomorrow.
(My usual laptop has died and is awaiting repair - everything important is backed-up to our network. I just need Worksite 8 installed on it's stand-in.)
Migrateduser
Good news all round - laptop fixed and code working, all I need to do now is tweak this for our requirements.
Many thanks!