Lotus Notes: Append the contents of a rich text field into another

25 pts.
Tags:
Lotus Domino
Lotus Notes
Hello, We have a ticketing system in Lotus Notes that has a rich text field allowing users to attach files, screenshots, links to other Notes document. The problem is that it is not possible to see who added what and when. My idea was to have a rich text field (maybe lite) that acts as a temporary field where a user can add documents and another rich text field that contains the complete history. So the user would add their documents to the temporary field and then when the document is saved, some code in the QuerySave action would move the contents of this temporary rich text field and append it to another existing field with a comment stating the user and timestamp. So the main rich text field would have the following sort of contents:
file1.txt
-- Added 010/1/2015 by user1
file2.doc
-- Added 31/01/2015 by user2
I have tried many of the solutions on the web to copy with the appendRTItem but none seem to work for my need. Does anyone have any ideas as to what I might be doing wrong or if I should be going about this in another way? I've lost count of the variations I have tried, but here is the last one in place, the temporary field is 'tmpAttachments' and the main field that should contain all attachments is called 'attachments'. the function copyAttachments is called from the Querysave function of the form. The modification doesn't have to be visible before the document is saved. Thanks for any help!
Function copyAttachments(source As Notesuidocument) As Boolean
Dim  s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim tdoc As NotesDocument
Dim vw As NotesView
Dim currItem As Variant
Dim targetitem As Variant
Dim seconditem As Variant
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument

Set db=s.CurrentDatabase
Set uidoc=ws.CurrentDocument
Set doc=uidoc.Document

If(doc.HasItem("tmpAttachments")) Then
Set currItem=doc.GetFirstItem("tmpAttachments")
Else
Set currItem=doc.CreateRichTextItem("tmpAttachments")
End If

If(doc.HasItem("attachments")) Then
Set seconditem=doc.GetFirstItem("attachments")
Else
Set seconditem=doc.CreateRichTextItem("attachments")
End If

Call seconditem.AppendRTItem(currItem)
Call currItem.remove()

source.Refresh True
End Function


Software/Hardware used:
IBM Notes 9 Social Edition
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Stiletto

    A few thoughts, but not necessarily any real answers:

    You've told us that you've made several attempts that didn't work, but you haven't told us what those attempts did.  How close to your end goal did you get?  For example, "I was able to get it to append the fields, but not in the order I wanted."

    Be careful with your variable names and function names; you don't want to inadvertantly use reserved names.

    In your code above, you're using GetFirstItem.  But, you will eventually wind up with a document that has multiple fields called "attachments" - not because of your code, but because Domino will automatically do this as your content exceeds what an individual field can hold.  I don't remember if the AppendRTItem call compensates for this.  But, maybe you could just keep adding fields with the same name.

    What if you move the Refresh call to the beginning of the code?  What if you don't make the Remove call?

    Just spitballing...

    5,545 pointsBadges:
    report
  • Andrew2
    Thanks for these pointers. most of the solutions I have tried just don't change the contents of the target field. In debug it looks like it is working, the contents move from one variable to another, but I reopen the document and nothing has changed.

    The closest I got was with this link

    http://ozinisle.blogspot.com/2010/01/lotusscript-code-to-transfer-contents.html

    With this I managed the move from a button, but it forced an immediate save and bypassed the rest of my querysave when I finally quit the document. So I removed the following lines when trying to implement it in the querysave.

    Call doc.Save(True,False)
        Call doc.ReplaceItemValue("SaveOptions","0")
        Call uidoc.Close
        set uidoc=ws.editdocument(true,doc)

    I moved the refresh but this didn't change anything. Same for the remove call. I'll check for reserved words.

    25 pointsBadges:
    report
  • Andrew2
    I seem to have got this working with the following function called from the postSave function. The result is a rich text field that the user can comment in or add attachments etc. Once saved these are appended into a new section on a non-editable rich text field with the title of the section being the user name and the date they were added. Now I just need to deal with the case where no comments were added and check on size limitations.

    Function copyAttachments(source As Notesuidocument) As Boolean
    	Dim  session As New NotesSession
    	Dim db As NotesDatabase
    	Dim doc As NotesDocument
    	Dim tdoc As NotesDocument
    	Dim vw As NotesView   
    	Dim sourceItem As Variant   
    	Dim sourceItemField As String
    	Dim targetItem As Variant
    	Dim targetItemField As String
    	Dim ws As New NotesUIWorkspace
    	Dim uidoc As NotesUIDocument
    	
    	Set db=session.CurrentDatabase
    	Set uidoc=ws.CurrentDocument
    	Set doc=uidoc.Document
    	
    	sourceItemField = "tmpAttachments"
    	targetItemField = "attachments"
    	
    	If(doc.HasItem(sourceItemField)) Then
    		Set sourceItem=doc.GetFirstItem(sourceItemField)
    	Else
    		Set sourceItem=doc.CreateRichTextItem(sourceItemField)
    	End If
    	
    	If(doc.HasItem(targetItemField)) Then
    		Set targetItem=doc.GetFirstItem(targetItemField)
    	Else
    		Set targetItem=doc.CreateRichTextItem(targetItemField)
    	End If
    	
    	' Create a new section in the target item and copy from the source	
    	Call targetItem.AddNewLine(1)
    	Call targetItem.BeginSection("----- " & session.commonUserName & " : " & Date$ & " : " & Time$ & " -----" ,,,True)	
    	Call targetItem.AddNewLine(1)
    	Call targetitem.AppendRTItem(sourceItem)   
    	Call targetItem.AddNewLine(1)
    	Call targetItem.EndSection()	
    	
    	' Delete the contents of the source item	
    	Call sourceItem.remove()
    	Call doc.Save(True,False)
    	Call doc.ReplaceItemValue("SaveOptions","0")
    	Call uidoc.Close
    	
    End Function
    Then I added the following line to the Postopen function

    Call doc.ReplaceItemValue("SaveOptions","1")

    25 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: