3
votes

There are two rich text fields in the form as well as two CKEditors in XPage.

1st one is editable and second one is computed.

User enters info (text, links , files & pictures etc) into 1st entry and the content should go to second rich text field which is non editable like log with user name and time stamp & content. Value comes from first field to second field like this once document is saved (post save event). Then we delete 1st field value.

We were doing the using AppendRTItem in lotus script. Now application has been converted to web; please let me know how this can be done so that two entries with mime part can be appended similar like AppendRTItem.

1
I wonder why this is down voted 2 times as this is a good question.Oliver Busse
@Oliver: that is the outcome of "First Posts" reviews - people with no knowledge about topic (XPages in this case) judge about quality of question ... and this is an example that they just downvote without any comment why they did. +1 for making up for them.Knut Herrmann
Can this question and its answer help you? stackoverflow.com/q/15121385/785061Per Henrik Lausten
Thanks for your comment. I had seen this post already. I am looking for append functionality; not actually this one.Subhasish Mukhopadhyay
I am able to make it using mime in lotus script agent called from postsave.Subhasish Mukhopadhyay

1 Answers

0
votes

This code work for me in LotusScript(but i dont test with pictures), try it. Rewrite it for ssjs/java if you need or use 'Run with document context' agent.

This code create mail with mime 'body' with attachment and append other mime element. Sorry for dirty code. I hope I could help you.

Private Function CreateMessage( xDoc As NotesDocument, xFrom As String, xSendTo As Variant, xSubject As String,  xBodyHTML As String, xFilepath As String ) As NotesDocument
    On Error GoTo Except

    Dim mail As NotesDocument
    Dim body As NotesMIMEEntity, bodyChild As NotesMIMEEntity, header As NotesMIMEHeader
    Dim stream As NotesStream
    Dim link As String
    Dim convertMime As Boolean
    convertMime = CommonTools_Session.Convertmime
    CommonTools_Session.Convertmime = False

    Set mail= CommonTools_GetSystemMailBox.CreateDocument
    res.ReplaceItemValue "Form", "Memo"
    res.ReplaceItemValue "PostedDate", CDat(Now)
    res.ReplaceItemValue "From", xFrom
    res.ReplaceItemValue "Subject", xSubject    
    res.ReplaceItemValue "SendTo", xSendTo
    res.ReplaceItemValue "Recipients", xSendTo

    Set body = mail.CreateMIMEEntity("Body")
    Set header = body.CreateHeader("Content-Type")
    Call header.SetHeaderValAndParams(|multipart/mixed;  boundary="boundary-example-1"; type=text/html|)

    Set stream = CommonTools_session.CreateStream   

    If xFilepath <> "" Then
        Set bodyChild = body.Createchildentity()
        Call bodyChild.SetContentFromText( stream, "text/html; charset=windows-1251", ENC_NONE )
        Call stream.Truncate()
        If stream.Open( xFilepath ) Then
            Set bodyChild = body.Createchildentity()
            Set header = bodyChild.Createheader( "Content-Disposition" )
            Call header.Setheaderval( {attachment; filename="Meeting minutes.xls"; charset=windows-1251} )
            Call bodyChild.Setcontentfrombytes( stream, "application/vnd.ms-excel", ENC_NONE )
            Call stream.Close()
            Call stream.Truncate()
            xBodyHTML = "<br><br>" + xBodyHTML
        Else
            Error 5001, "Cannot open file"
        End If
    End If

    Dim mime As NotesMIMEEntity
    Set mime = xDoc.Getmimeentity( "MM_BodyAgenda" )
    If Not mime Is Nothing Then
        Set bodyChild = body.Createchildentity()
        Call bodyChild.Encodecontent( ENC_NONE )
        Call appendMimeToBody( mime, bodyChild )
    End If

    Call stream.WriteText( "<br><br>" + link + "<br><br>" + xBodyHTML + "<br>" + link + "<br><br>", EOL_NONE )
    Set bodyChild = body.Createchildentity()
    Call bodyChild.SetContentFromText( stream, "text/html; charset=windows-1251", ENC_NONE )

    Call mail.CloseMIMEEntities( True, "Body" )

    Set CreateMessage = mail
    CommonTools_Session.Convertmime = convertMime
End Function




Sub appendMimeToBody( xMime As NotesMIMEEntity, xBody As NotesMIMEEntity)
    Dim ct, cst, thisname, hn, hv, thishead
    ct = xMime.ContentType
    cst = xMime.ContentSubType
    Dim encoding As Integer
    encoding = xMime.Encoding
    Dim stream As NotesStream
    Dim ttCharset As String
    ttCharset = "utf-8"
    thisname = "" ' name of file if this part is an attachment

    ForAll header In xMime.HeaderObjects ' handles Subject and other headers
        hn = header.HeaderName
        If hn="Content-Type" Then
            thisname = header.GetParamVal("name") ' could be filename
        End If
        If Not (hn="Content-Type" Or hn="X-Notes-Item" ) Then ' don't pass X-Notes-Item ' 
            hv = header.GetHeaderValAndParams
            Set thishead = xBody.CreateHeader(hn)
            Call thishead.SetHeaderValAndParams(hv)
        End If
    End ForAll

    If ct="multipart" Then
        Set thishead = xBody.CreateHeader("Content-Type")
        Call thishead.SetHeaderVal(ct+"/"+cst + {; charset="} + ttCharset + {"; boundary="boundary-example-1} + "qqqqwerty" + {"} )
        xBody.Preamble = xMime.Preamble
        Dim child As NotesMIMEEntity
        Dim outchild As NotesMIMEEntity
        Set child = xMime.GetFirstChildEntity
        Do While Not child Is Nothing
            Set outchild = xBody.CreateChildEntity
            Call doPart(child, outchild)
            Set child = child.GetNextSibling
        Loop
    Else ' pass unchanged
        Set stream = CommonTools_Session.CreateStream
        Call xMime.GetContentAsBytes(stream, False)
        Dim s As String
        s = stream.ReadText()
        Dim b As Variant
        b = stream.Read()
        If Trim(thisname)="" Then
        If ct = "text" And cst = "html" Then Call stream.Writetext( "<br><br><br>" )
            Call xBody.SetContentFromBytes(stream, ct+"/"+cst+{;charset="} + ttCharset + {"}, encoding)
        Else
            Call xBody.SetContentFromBytes(stream, ct+"/"+cst+{;charset="} + ttCharset + {";name=}+thisname, encoding)
        End If
    End If
End Sub