1

enter image description here

Body content is null in document properties showing this sign ""[] instead of content.
Also messsage box lotus script is showing null with getItemValue("Body").
How to resolve this ?

Sub Click(Source As Button)
    Dim s As NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim col As NotesDocumentCollection

    Set s = New NotesSession
    Set db = s.CurrentDatabase


    Set col = db.UnprocessedDocuments

    Print "Collection Size:"& col.Count
    Set doc = col.GetFirstDocument
    If doc.HasItem("Body") Then
        While Not doc Is Nothing
            Dim body As Variant


            body = doc.GetItemValue("Body")

            Msgbox (body(0))

            Set doc = col.GetNextDocument(doc)
        Wend
    End If
End Sub
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Could you show us some code? What is selected when the document properties box is displayed? Categories will not have any body, so make sure you are selecting a document. If you are running agents on selected docs, categories will not return any document properties. – teleman Apr 23 '20 at 14:52
  • Sub Click(Source As Button) Dim s As NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim col As NotesDocumentCollection Set s = New NotesSession Set db = s.CurrentDatabase Set col = db.UnprocessedDocuments Print "Collection Size:"& col.Count Set doc = col.GetFirstDocument If doc.HasItem("Body") Then While Not doc Is Nothing Dim body As Variant body = doc.GetItemValue("Body") Msgbox (body(0)) Set doc = col.GetNextDocument(doc) Wend End If End Sub – Muhammad Saleh Apr 24 '20 at 05:54
  • above is my code I can get subject, delivered_to, from e.t.c with this code but body is coming null. don't know why. – Muhammad Saleh Apr 24 '20 at 05:56
  • See the GetItemValue method in the Help: "The return value is ... an array of values for text, number, or time-date items, and a string for rich text items.". So, in your code, body is a String and hence body(0) is invalid. – D.Bugger Apr 24 '20 at 08:44
  • so what should I do actually I am a java developer and lotus script beginner – Muhammad Saleh Apr 24 '20 at 09:10

2 Answers2

1

Because (usually) Body is a Rich Text field, and these fields are treated differently. See the NotesRichTextItem in the Designer Help.

Starting from your code:

Set s = New NotesSession
Set db = s.CurrentDatabase


Set col = db.UnprocessedDocuments

Print "Collection Size:"& col.Count
Set doc = col.GetFirstDocument
While Not doc Is Nothing
    Dim body As Variant

    If doc.HasItem("Body") Then
        Set body = doc.GetFirstItem("Body") ' now body contains the richtext item'

        Msgbox body.UnformattedText
    End If
    Set doc = col.GetNextDocument(doc)
Wend

Notes should convert the MIME item to rich text for you. If you want to deal with the MIME type, you have to use the NotesMimeHeader and NotesMimeEntity classes. See the Help database, especially the examples on these classes are interesting.

D.Bugger
  • 2,300
  • 15
  • 19
  • I do look after NotesRichTextItem(LotusScript) and tried few example but am facing an error variant does not contain an object. can you please share an working example of it. – Muhammad Saleh Apr 24 '20 at 07:32
  • That's not the idea of this website IMHO. It's better that you share your non-working example, and we help you get it working. If you have to post your code, please modify the question and add it there, in a code section. – D.Bugger Apr 24 '20 at 08:32
  • I also shared the picture of document body property please look my modified question – Muhammad Saleh Apr 24 '20 at 13:36
0

You cannot just reference a NotesRichtTextItem the same way you reference an ordinary NotesItem. A rich text field can contain graphics, tables, fonts, colors, and other things that are not text. It does not matter if it actually does contain those things; it is never a simple array of strings, so Body(0) is not defined. Look up the methods of the NotesRichTextItem class. You will find one called getUnformattedText which will return a simple text representation of the field value.

(There are options for getting the field value as HTML so that you get all the formatting tags, too, but only if the field is really stored as MIME instead of Notes rich text.)

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • field tyoe is mime its confirm. – Muhammad Saleh Apr 24 '20 at 12:52
  • I also shared the picture of document body property please look my modified question – Muhammad Saleh Apr 24 '20 at 13:36
  • You still can't use Body(0). You need to use Body.getUnformattedText. – Richard Schwartz Apr 24 '20 at 17:47
  • Or you need to learn how to use the NotesMIMEEntity class and the other NotesMIMExxx classes that are related to it. MIME fields are related as a tree of entities. Your Body field is a top-level entity. You may be able to just use GetEntityAsText. Otherwise, you would to find its children, and maybe their children, until you find the part (or parts) where the ContentType/ContentSubType is text/plain or text/HTML, and then you can use getContentAsText or getContentAsBytes -- and you may need to use DecodeContent along the way if there is a Content-Transfer-Encoding header. – Richard Schwartz Apr 24 '20 at 17:47
  • i used the notes NotesMIMEEntity class already and I am getting headers but nor content type neither content as text both are still null. – Muhammad Saleh Apr 26 '20 at 07:15
  • Then it's probably time for you to open a new question, showing your new code, and explaining your new problem. – Richard Schwartz Apr 26 '20 at 20:42