I’m trying to edit a rich text field in a uidocument. I need to edit some things (related to table properties) which I can’t edit through lotusscript. My problem is that I cannot seem to bring the new notesuidocument back into editmode. I get a user-defined error on the last line of the code. I have also tried to uidoc.reload method to no avail. Anyone know I I can get this document back into editmode with the changes?
Dim mywk As New notesuiworkspace
Set uidoc2 = mywk.CurrentDocument
If uidoc2.EditMode Then
uidoc2.save
End If
Dim docdxl As String
Dim docunid As String
Dim curdoc As notesdocument
Set curdoc = uidoc2.document
docunid = curdoc.UniversalID
'export
Dim exporter As NotesDXLExporter
Set exporter = cfs.CreateDXLExporter
docdxl = exporter.Export(curdoc)
'change example (just testing now)
docdxl = replacesubstring(docdxl, "change this text", "crompton was here")
'import
Dim importer As NotesDXLImporter
Set importer = cfs.CreateDXLImporter(docdxl, cfdb)
importer.DocumentImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Call importer.Process
'bring the changes back into the uidoc
Call uidoc2.Close
Set curdoc = cfdb.getdocumentbyunid(docunid)
Set uidoc2 = mywk.EditDocument(True, curdoc)
Subject: editing a notesuidocument with DXL
I’m not getting the error any longer, but I still can’t seem to load the changed document back into the ui. When the new uidoc loads, the backend changes are not shown. If I manually close and reopen the document, I see the changes made through DXL. Any help is greatly appreciated.
Here’s the code in a button on the form:
Dim wk As New notesuiworkspace
Dim uidoc As notesuidocument
Dim uidocnew As notesuidocument
Dim curdoc As notesdocument
Dim curdocnew As notesdocument
Dim rti As NotesRichTextItem
Set uidoc = wk.CurrentDocument
Set curdoc = uidoc.Document
If uidoc.EditMode Then
uidoc.save
End If
Dim docdxl As String
Dim docunid As String
docunid = curdoc.UniversalID
'export
Dim exporter As NotesDXLExporter
Set exporter = cfs.CreateDXLExporter
docdxl = exporter.Export(curdoc)
'change
docdxl = replacesubstring(docdxl, "change", "crompton")
'import
Dim importer As NotesDXLImporter
Set importer = cfs.CreateDXLImporter(docdxl, cfdb)
importer.DocumentImportOption = DXLIMPORTOPTION_UPDATE_ELSE_IGNORE
Call importer.Process
'bring the changes back into the uidoc
Set curdocnew = cfdb.getdocumentbyunid(docunid)
curdoc.saveoptions = "0"
Call uidoc.Close
Set uidocnew = wk.EditDocument(True, curdoc)
Subject: RE: editing a notesuidocument with DXL
Try getting rid of curdoc and the uidoc before getting curdocnew. The problem is that the call to the back-end document will refer to the in-memory version for as long as that reference remains valid (Notes will see that it’s already got the document you’re asking for, and simply give you a new pointer to the same thing).
Subject: RE: editing a notesuidocument with DXL
THANKS STAN!!
I’ve been struggling over this for about 6 hours. I appreciate your help. It works now!
One more question:
I’ve read that it’s not a good idea to use a string from my NotesDXL exporter (there’s a 64K limit on the manipulated string). Elsewhere in the forum you recommend using a NotesDOMParser to edit the XML. Can you tell me how to get my NotesDXLExporter to export something accessible through NotesDOMParser, and then take this and pull it back into a NotesDXLImporter? Any suggestions would shaves hours off my learning curve – this is my first time using DXL.
Thanks,
Chris
Here’s the code:
Dim wk As New notesuiworkspace
Dim uidoc As notesuidocument
Dim uidocnew As notesuidocument
Dim curdoc As notesdocument
Dim curdocnew As notesdocument
Dim rti As NotesRichTextItem
Set uidoc = wk.CurrentDocument
Set curdoc = uidoc.Document
If uidoc.EditMode Then
uidoc.save
End If
Dim docdxl As String
Dim docunid As String
docunid = curdoc.UniversalID
'export dxl
Dim exporter As NotesDXLExporter
Set exporter = cfs.CreateDXLExporter
docdxl = exporter.Export(curdoc)
'change dxl
docdxl = Replace(docdxl, "change", "crompton")
'import dxl
Dim importer As NotesDXLImporter
Set importer = cfs.CreateDXLImporter(docdxl, cfdb)
importer.DocumentImportOption = DXLIMPORTOPTION_UPDATE_ELSE_IGNORE
Call importer.Process
'get rid of old doc
curdoc.saveoptions = "0"
Call uidoc.Close
Delete curdoc
Delete uidoc
'bring the changes back into the uidoc
Set curdocnew = cfdb.getdocumentbyunid(docunid)
Set uidocnew = wk.EditDocument(True, curdocnew)
Subject: RE: editing a notesuidocument with DXL
Replace shouldn’t cause any problems; it’s when you want to splice in new stuff that you have to consider the limit.
Setting up the pipeline is easy; you simply declare and set an Exporter, a DOMParser and an Importer. Set the output of the Exporter to the DOMParser, and set the output of the DOMParser to the Importer. (The input of the exporter and output & settings of the importer are good as they are.) When you call Process on the Exporter, the whole thing kicks off, and the document will be parsed. That fires an event trigger in the NotesDOMParser that you need to intercept:
On Event PostDOMParse From domParser Call MyDXLManglingSub
That line has to appear AFTER the DOMParser has been declared and set, but before the Process is called on the Exporter.
Sub MyDXLManglingSub(Source As NotesDOMParser)
'mangle XML here
End Sub
The Designer Help examples are actually pretty good here, and handling the XML is pretty much the same as manipulating a web page using DOM methods. You use things like GetElementByID and GetElementsByTagName to get hold of the document nodes and so forth, and add new items using document.CreateElement, document.CreateTextNode, and the like, then using node.AppendChild to file the new elements where they belong in the document. There are references and sample code all over the web for this stuff.
One warning though – you absolutely cannot use long object-dot-property-dot-method-dot-property-dot-method chains in this code. Every object or collection needs to be declared and set along the way, one dot at a time. Make that two warnings – the concept of Null is handled differently in the DOM classes from the rest of LotusScript. DOM objects will almost never be Nothing, instead element.IsNull will return True.
Once you’re done playing with the document, use Serialize to pass the result back to the Importer, and you have your new document in the database.
Subject: RE: editing a notesuidocument with DXL
Thanks for all your help, Stan. I think this is going to work!
Chris