0
votes

I have a notes form with a rich text field on it, called "Body". I've set the "Storage" property of the field to "Store contents as HTML and MIME".

Now, I am creating a new document with that form in the Notes Client.

However, if I try to access the rich text field's value in SSJS with NotesRichTextItem.getMIMEEntity(), it always returns null.

Am I missing something?

Thank you for your help in advance.

Update 2: 02/12/2015

I did some more testing and I found the cause, why it won't recognize the rich text field as MIME Type, but rather always returns it as RICH TEXT:

The cause is me accessing the database with "sessionAsSigner" rather than just using "database".

If I remove "sessionAsSigner" and use "database" instead, making the XPage unavailable to public access users, so, I am forced to log in, the code recognizes it as MIME Type and I can get a handle on NotesMIMEEntity.

Unfortunately, the XPage has to be available to public access users and I have to use sessionAsSigner.

When I open the document properties and I look at the rich text field, I can see that the "Field Flags" are "SIGN SEAL". My guess is, that's why sessionAsSigner doesn't work, but it is just a guess.

Any ideas?

Update 1: 02/12/2015

Here is the code I am using in my SSJS:

var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;

var sServer = session.getServerName();

oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();

//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))

//Get body text
var oItem:NotesItem = oDocMailProfile.getFirstItem("Body");
var entity:NotesMIMEEntity = oItem.getMIMEEntity();

//Create email body
var tmp = entity.getContentAsText();

//Replace <part2> with part 2 of the password
tmp = @ReplaceSubstring(tmp, "&lt;part2&gt;", sPWPart2);

//Set content of Body field as MIME type                                            
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();                                
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);        

//Send email
oDocMail.send();

As I mentioned before, I've also tried:

var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;

var sServer = session.getServerName();

oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();


//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))

//Get body text
var entity:NotesMIMEEntity = oDocMailProfile.getMIMEEntity('Body');

//Create email body
var tmp = entity.getContentAsText();

//Replace <part2> with part 2 of the password
tmp = @ReplaceSubstring(tmp, "&lt;part2&gt;", sPWPart2);

//Set content of Body field as MIME type                                            
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();                                
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);        

//Send email
oDocMail.send();
3

3 Answers

3
votes

Try calling sessionAsSigner.setConvertMime(false)

0
votes

You get the MIMEEntity from the document, not from the Richtext item. See an example here (starting at line 103): https://github.com/zeromancer1972/OSnippets/blob/master/CustomControls/ccSnippets.xsp

0
votes

You should set the session to not convert MIME to RichText. Add this at the start of your code.

session.setConvertMime(false);