Hi, i have a script working to add a file to the database, but it doesn't work for a specific folder in a workspace.
for some reason, casting to IManDocumentfolders doesn't work. It gives this error:
VBScript runtime error: Type mismatch: 'IManDocumentFolders'
When i don't cast, i get this:
VBScript runtime error: Object doesn't support this property or method: 'ws.DocumentFolders'
Below is the piece of code i would like to use, but doesn't work:
Set ws = results.ItemByIndex(1) 'assuming there's only 1 workspace
Set folders = IManDocumentFolders(fldres)
Set fldres = ws.DocumentFolders
For Each fld In folders
If fld.Name = fldDest Then
Set target = fld
MsgBox target.Name
Else
MsgBox "Folder not found in workspace ..."
End If
Next
I also need to cast to IManDocument3, but i assume it's the same thing i'm doing wrong
Set doc = db.CreateDocument
Set doc3 = IManDocument3(doc)
I've looked for examples in vbscript, but i can't find anything similar. I have the code working in VB, but i also need a vbscript version.
Anyone any ideas? :-)
(below my full code)
public Sub MoveToDMS()
'** ENUMERATIONS **
Const imFolderName = 3
Const imFolderOwner = 4
Const imProfileAuthor = 5
Const imProfileOperator = 6
Const imProfileType = 7
Const imProfileClass = 8
Const imProfileDescription = 3
Const imProfileName = 4
Const imProfileComment = 24
Const imProfileCustom1 = 25
Const imProfileCustom3 = 27
Const imProfileCustom7 = 31
'Destination info vars
Dim ServerName, DatabaseName
ServerName = "BEBRUAPP30" 'Destination Server
DatabaseName = "DMS-PROD" 'Database Name
'iwov sdk objects
Dim dms, sess, db, doc, doc3, wps, fld, target
Set dms = WScript.CreateObject("Imanage.ManDMS")
Set sess = dms.Sessions.Add(ServerName)
'sess.Login "username", "password"
sess.TrustedLogin
Set db = sess.Databases.ItemByName(DatabaseName)
Set wps = dms.CreateFolderSearchParameters
wps.Add imFolderName, fldName
wps.Add imFolderOwner, sess.UserId
Set dblist = WScript.CreateObject("Imanage.ManStrings")
dblist.Add db.Name
Set results = sess.WorkArea.SearchFolders(dblist, wps)
if results.Empty = true then
MsgBox "No results returned based on the search criteria."
sess.Logout
Else
Set ws = results.ItemByIndex(1) 'assuming there's only 1 workspace
Set fldres = ws.DocumentFolders
Set folders = IManDocumentFolders(fldres)
For Each fld In folders
If fld.Name = fldDest Then
Set target = fld
MsgBox target.Name
Else
MsgBox "Folder not found in workspace ..."
End If
Next
End if
Set doc = db.CreateDocument
'set properties for document to be added
doc.SetAttributeByID imProfileAuthor, sess.UserId 'author
doc.SetAttributeByID imProfileOperator, sess.UserId 'operator
doc.SetAttributeByID imProfileType, attAppl 'application
doc.SetAttributeByID imProfileClass, attType 'content type
doc.SetAttributeByID imProfileDescription, attDesc 'description
doc.SetAttributeByID imProfileName, attName 'filename
doc.SetAttributeByID imProfileComment, attCmmt 'comment
doc.SetAttributeByID imProfileCustom1, attClnt 'client
doc.SetAttributeByID imProfileCustom3, attUlpt 'ultimate parent
doc.SetAttributeByID imProfileCustom7, attPtnr 'partner
Set doc3 = IManDocument3(doc)
'check in document
'Set checkin = doc.CheckInWithResults(SourceFile, imCheckinNewDocument, imDontKeepCheckedOut)
Set checkin = doc3.CheckInExToFolderAsNewDocumentWithResults(src File, imCheckinOptions.imDontKeepCheckedOut, target, IManage.imHistEvent.imHistoryCheckin, "1", "2", "3")
If checkin.Succeeded = True Then
MsgBox "Your document is in " & db & VbCr & "Number # " & doc.Number & VbCr & "Object ID is " & doc.ObjectID
Else
For intLoop = 1 To checkin.ErrorList.Count
Call MsgBox("Error with AttribID: " & checkin.ErrorList.ItemByIndex(intLoop).AttribID)
Next
End If
End Sub