Home
TeamSite
Profiling and opening documents in Word
MikeatBDB
Hi
We are currently migrating to Office 2003 and iManage8 and we have a problem. We are going to use matter centric profiling but we will be using multiple document types (Classes) within a folder. Our users do not want to enter informationon two dialogs before profiling. We have designed a dilaog that will sort out this problem from within word but we cannout check the document out and open it so that when we save the document it is not treated as a SaveAs.
We are using the OpenCmd to try and open it
Here is the code we are using to import in the standard document and then open it
Set objDocument = oDatabase.CreateDocument()
' 'Set the profile info
objDocument.SetAttributeValueByID nrClass, strDocType
objDocument.SetAttributeValueByID nrCustom2, strMatterNo
objDocument.SetAttributeValueByID nrCustom1, strClientNo
objDocument.SetAttributeValueByID nrDescription, strRe
objDocument.SetAttributeValueByID nrType, strApplication
objDocument.SetAttributeValueByID nrOperator, strUser
objDocument.SetAttributeValueByID nrAuthor, strAuthor
objDocument.SetAttributeValueByID nrCustom3, strDept
Dim fs As Object
Set objDoc = objDocument.CheckIn(strFullName, nrNewDocument, nrDontKeepCheckedOut, err)
Dim lDocNumb As Long
Dim lVersion As Long
lDocNumb = objDoc.Number
lVersion = objDoc.Version
If strFolderId <> "" Then
'we have the folder id so use that to get the folder
Set objFolder = oDMS.GetObjectByID(strFolderId)
objFolder.Documents.Add objDoc
End If
MsgBox "Profiled as " & lDocNumb & "_" & lVersion
'Delete the temporary file - strfullname holds the temporary file name
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile strFullName, True
Set fs = Nothing
Set objDoc = Nothing
Set objDoc = oDatabase.GetDocument(lDocNumb, lVersion)
'This code using OpenCmd should get the document with the prf file
Dim pOpenCmd As imanextlib.OpenCmd
Dim oContext As imanextlib.ContextItems
Set oContext = New imanextlib.ContextItems
Dim pArrDox(0) As IManage.NRTDocument
Set pOpenCmd = New imanextlib.OpenCmd
Set pArrDox(0) = objDoc
oContext.Add "ParentWindow", GetActiveWindow()
oContext.Add "SelectedNRTDocuments", pArrDox
'No error reported
oContext.Add "IManExt.OpenCmd.NoCmdUI", True
oContext.Add "IManExt.OpenCmd.Integration", False
pOpenCmd.Initialize oContext
pOpenCmd.Update
Dim fileLoc As String
If pOpenCmd.status = (pOpenCmd.status And nrActiveCommand) Then
pOpenCmd.Execute
'fileLoc = oContext("IManExt.OpenCmd.ING.FileLocation")
End If
Set oContext = Nothing
Set pOpenCmd = Nothing
Set objNew = Nothing
Our problem is that it does not run the standard macros we normally have attached and the document that is opened when saved is treaded as a local document.
Any help please
Thanks
Mike
Bircham Dyson Bell
Find more posts tagged with
Comments
jny
So, this Office document you're importing to WorkSite has a macro in it? What does this macro do when the document is opened by the OpenCmd? Could you send in a copy of the actual Office document that has this macro?
I'm not sure what you mean by "the [WorkSite] document, when saved, is treated as a local document after it is was opened via the OpenCmd Object." Do you mean that if the end-user selected, for instance, File | Save or Ctrl-S, the document is saved silently? If so, then this is the expected behavior on the currently opened WorkSite Document. If you mean something else, could you describe the behavior in more details? And, what do you think the expected outcome should be?
Btw, after you have imported (via the Checkin Method) the new Office document, you shouldn't need to make an additional GetDocument call to get the handle to the same document object back since you already have a pointer to the document at the Checkin call. If it's necessary to get the latest copy of the document from the DMS, you may call Refresh; this method is used to get the latest from the server.
Also, this is minor, but the IManExt.OpenCmd.NoCmdUI and IManExt.OpenCmd.Integration ContextItems serve no purpose when you're calling the OpenCmd to open the document in its native editor. These two ContextItems are used for the purpose of checking out the document, along with its PRF file, to the portable directory without opening it in its native app. You may then do something with the checkoutpath to this checked out document. The checkoutpath can be queried by IManExt.OpenCmd.ING.FileLocation ContextItem.
MikeatBDB
Jny
Thanks for that. I have managed to see what was causing the problem with the macros in my document but the problem that is making me tear my hair out is getting the document in Word after I have retrieved it from the database and then saving it. When I save the document that is opened it does a SaveAs instead of a save. It tried to import the document for a second time. If I just put the values in the profile details dialog from code it works correctly but when I try and use the OpenCmd to open the document without using the dialog, it is treated as another document to import. I have look ed the Worksite properties for the document and they are all fine. We need to be able to check out the documents for portable mode using this dialog as well so that is why I want to generate the PRF file and hence I am using the OpenCmd dialog.
Hope this clarifies my problem
Thanks
Mike
Bircham Dyson Bell
jny
The OpenCmd Object is used to checkout the WorkSite document to the portable directory (along with its prf file) and to open it in its native app. The ContextItems, IManExt.OpenCmd.NoCmdUI and IManExt.OpenCmd.Integration, are not needed for this to happen.
It's strange that it would attempt to do a Save As (I presume you mean Office Integration is prompting you via the Save As dialog to save it as a new document) on a WorkSite document opened in Word. When your WorkSite document is opened in Word -- using your OpenCmd implementation -- does the document window title indicate that the document belongs to WorkSite, i.e., does it read #[DOCNUM]v[VERSION]<DATABASE> - <DESCRIPTION>?
I used the code below to create a new document and import it to the preferred database, added a reference to the new document in the specified folder, then used OpenCmd to open the document in Word. I then edited the document which was now opened in Word, selected File | Save, and it did not prompt the Save As dialog for me to save it as a new document -- as it should not have had. A reference to the new document was also successfully added to the specified folder.
[VB]
Option Explicit
Private Sub Form_Load()
Dim dms As New NRTDMS
Dim sess As NRTSession
Dim newDoc As NRTDocument
Dim fldr As NRTFolder
Dim context As contextitems
Dim cmd As OpenCmd
Dim arrDox(0) As NRTDocument
Dim es
Const importPath = "C:\Temp\Dummy Docs\test.DOC" ' local file path to the new document
Const fldrID = "!nrtdms:0:!session:<MYSERVER>:!database:<MYDATABASE>:!folder
rdinary,21:" ' my folder moniker
On Error GoTo oops
Set sess = dms.Sessions.Add("<MYSERVER>")
sess.TrustedLogin
Set newDoc = sess.PreferredDatabase.CreateDocument
With newDoc
.SetAttributeValueByID nrAuthor, sess.UserID
.SetAttributeValueByID nrOperator, sess.UserID
.SetAttributeValueByID nrClass, "MEMO"
.SetAttributeValueByID nrType, "WORD"
.SetAttributeValueByID nrDescription, "New doc created using VB."
End With
newDoc.CheckIn importPath, nrNewDocument, nrDontKeepCheckedOut, es
MsgBox newDoc.Number & "_" & newDoc.Version
If False = newDoc.CheckedOut Then
' Get folder
Set fldr = dms.GetObjectBySID(fldrID)
' Add a reference to the new document to the folder
If fldr.IsOperationAllowed(nrAddDocumentFolderOp) Then
fldr.Documents.Add newDoc
fldr.Update
End If
' Open the new document using OpenCmd
Set context = New contextitems
Set cmd = New OpenCmd
' Put the document object in a safe array
Set arrDox(0) = newDoc
' Required values
context.Add "ParentWindow", Me.hWnd
context.Add "SelectedNRTDocuments", arrDox
cmd.Initialize context
cmd.Update
If cmd.Status = (cmd.Status And nrActiveCommand) Then
cmd.Execute
End If
End If
GoTo cleanup
oops:
Dim iErr As NRTProfileError
Set iErr = es(0)
GoTo cleanup
cleanup:
If sess.Connected Then
sess.Logout
dms.CloseApplication
End If
Set newDoc = Nothing
Set fldr = Nothing
Set context = Nothing
Set cmd = Nothing
Set sess = Nothing
Set dms = Nothing
End
End Sub
You mentioned: "We need to be able to check out the documents for portable mode using this dialog as well so that is why I want to generate the PRF file ..." To which dialog does "this dialog" refer? Sorry, but I'm getting confused.
MikeatBDB
Jny
Thanks for that. The major problem I have though is that I am trying to create, checkin and open a document from within word without using the iManage dialogs. We need to use a single dialog for this process and the imanage solution uses two dialogs one to open the correct folder and a second to set the details of the docment. We have to choose the class at the time of saving as each of our folders can have multiple classes assciated with them. The code I posted will do this but the problem is that it always calls the BeforeDocuemntSaveAs event of the extenisibilty object. As it does this it will call the dialog we have written to get the information for the profile.
The aim of this is to do everything sliently after I have all the required profile information. That is the reason I am trying to use the IManExt.OpenCmd.NoCmdUI instruction. Is there an equivalent command for the import dialog?
Hope this clarifies the question?
Thanks for your help
Mike
Bircham Dyson Bell
Edited by MikeatBDB on 02/08/05 07:10 AM (server time).
jny
The context in which you're implementing the OpenCmd was a crucial piece of info to know right from the beginning, as it determines what the required contextitems to use and more...
Since you're already in an instance of Word, instead of opening the doc in another instance of Word, you should get the file location from the ContextItems Collection and use Documents.Open to open it from your code (i.e., macro, COM-Addin, etc.). The reason you'd want to avoid launching another instance of Word is that the OpenCmd will try to open Word but fails because Word is already launched -- since OpenCmd is executed from within your macro, which in turn is inside a process already -- thus it creates a dead lock.
Example code to demonstrate using OpenCmd to open a WorkSite document from within Word:
[VBA]
If Not pDoc Is Nothing Then
'''''' Use OpenCmd to open doc
Dim objContext As IMANEXTLib.ContextItems
' Pointer to ContextItems for command
Dim pCmd As IMANEXTLib.OpenCmd
' Pointer to command object
Dim arrDox(0) As IManage.NRTDocument
' Array to hold selected document
' Create an instance of ContextItems Collection
Set objContext = New IMANEXTLib.ContextItems
' Create an instance of OpenCmd object
Set pCmd = New IMANEXTLib.OpenCmd
' Pass document object to array
Set arrDox(0) = pDoc
' Add required values to objContext
objContext.Add "SelectedNRTDocuments", arrDox
objContext.Add "IManExt.OpenCmd.Integration", True
' This lets iManExt knows that it's from integration
objContext.Add "IManExt.OpenCmd.NoCmdUI", True
' This keeps it from opening doc in another instance of Word;
' thus, avoids deadlock
' Initialize command object
pCmd.Initialize objContext
' Update command object
pCmd.Update
' Check status: use bitwise operation
If pCmd.Status = (pCmd.Status & nrActiveCommand) Then
' Execute cmd
pCmd.Execute
Dim filLoc As String
filLoc = objContext("IManExt.OpenCmd.ING.FileLocation")
' Put file location of the open doc in filLoc
Documents.Open (filLoc)
' Use Word to open doc so that it's within the same Word process;
' thus prevents deadlock
'Remove context items
objContext.Remove "SelectedNRTDocuments"
objContext.Remove "iManExt.OpenCmd.Integration"
End If
End If
Actually, similar info is documented in the SDK: WorkSite Extension Library Reference Manual.pdf: Chapter 4: OpenCmd: Optional Values: iManExt.OpenCmd.Integration.
MikeatBDB
Jny
I have tried this and the problem still remains. The document is opened but it will not do a save only a save as. This is the only problem I now have with this. The example I am trying to do is that I create a basic letter and check it in and reopen before the main text of the letter is entered. This is to make sure everything is front end profiled. Once the rest of the letter is typed, the user should be able to save the docuemnt back into iManage but it always treats it as a save as.
I am at a complete dead end with this and I can't think of anything else I can do.
Thanks for your help
Mike
Bircham Dyson Bell
jny
I would need to see your code -- not code snippet but your working project/macro. Something must be off... I won't be able to help you without being able to recreate it on my end.
Also, you never did let me know whether or not the document window title indicates that the document belongs to WorkSite. That is, does it read #[DOCNUM]v[VERSION]<DATABASE> - <DESCRIPTION>?
guido1
Mike,
I think you need to capture the Extensibility object's IManFileSave event, rather than executing the CreateDocument method and then using the OpenCmd object.
Using the event, fetch a pointer to the IManFileSaveCmd object, and in its OnInit event set your profile attributes (Class, Subclass, whatever), and let Worksite do the rest of the save procedure for you.
hoping I've understood you correctly..
Guido
andrewdemmon
Hi thanks for both of your comments.
I am trying to complete this project while Mike is off on holiday so please excuse my ignorance if I have missed anything that you have already gone over.
Before I start, Jny in your post, you asked what was in the window title. We have the exact same as you have set out.
From what I can see, the final problem that we are having is when ever we are doing a save or save as. In the objExtensibilitySink_DocumentBeforeSaveAsOptions event we have some code that will show our custom single profile screen. This is why currently everytime we do a save or a save as the profile screen is shown again as Mike mentioned in previous posts. This is OK if we did click on save as, as we would probable need to profile in another document but if we click on the save button we simply need the document to do a normal save.
Is there any way that you know of that we can distinguish in the objExtensibilitySink_DocumentBeforeSaveAsOptions between a save or a save as so that we can only perform the code to show the profile screen if a save as has been executed.
Hope this makes some sense. I am fairly new to this iManage development.
Many thanks
Andy
jny
No, there is a way to predetermine the save behavior the user has selected through this event handler.
guido1
Although you can't distinguish between a Save and Save when implementing the Extensibility object's DocumentBeforeSaveAsOptions event, you could try a more brutish method by customising the Word user interface: create a public Word VBA function such as FileSaveCustom that exhibits all the business rules you need, then re-create the FileSave icon on Word's Standard toolbar, as well as the menu option under the File popup menu. Set this custom button's OnAction property to FileSaveCustom, then hide Word's native Save buttons.
Remember that you'd have to do the same for Word's keybindings (shortcut keys) such as Ctrl+S. This is what the iManO2k.dot file already does, so you'd either need to edit this to match your custom function, or remove it altogether and apply the keybindings yourself.
Of course then you have the fairly hellish task of remembering that these customisations have been made, and managing them, ie. remembering to not deploy the out-of-the-box iManO2k.dot file for example.
jny
Could this custom profile dialog be prompted after the document is saved -- in which case you would know if the document were saved as a NewVersion/NewDocument/neither? What is the user input that you would need before the save? If it's something that you can post-append to the document, then it would be a cleaner solution.
Tell me more about what you're trying to accomplish.
MikeatBDB
We have been given a different way of look at this so we do not need to investigate this any further. I do not have the alternate solution until Andy gets back from Holidaybut when I do I will post it up.
Thanks for all your help
Regards
Mike
Bircham Dyson Bell