This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Nov 21, 2013, 4:32 PM
18 Posts

can't copy a RT item to another document

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 16
I have a button on an xPage that should be sending the backend document as an email.  Most of it works, but I need to send the rich text "Body" field, and that part is not working.  
I always get a completely empty body field.  I've tried several ways to do this, and this is what I have now (that still sends an empty body field):

var db = session.getCurrentDatabase;
var doc = currentDocument.getDocument(true);
var u = @Name("[CN]", @UserName());
var t = currentDocument.getItemValueString("SendTo");
currentDocument.save(); // I'm saving to at least be able to LOOK at the fields on the document - they are correct
doc.save(); // added a backend save, to see if that would help
var memo = db.createDocument();
memo.replaceItemValue("Form","Memo");
memo.replaceItemValue("From",u);
memo.replaceItemValue("SendTo",currentDocument.getItemValueString("SendTo");
var body = memo.createMIMEEntity();
var stream = session.createStream();
var entity:NotesMIMEEntity = doc.getMIMEEntity("Body");
stream.writeText(entity.getContentAsText()); // I used to be able to get the text from a message, but that no longer works
entity.setContentFromText(stream,"text/html;charset=iso-8859-1", 0);

var subject = body.createHeader("Subject");

subject.setHeaderVal(currentDocument.getItemValueString("Subject"));

memo.send(t);

stream.close();

Nov 21, 2013, 4:54 PM
18 Posts
what if you want more than text?

I actually did try using a RichTextItem also.  I don't need to append it, I want to COPY an existing rich text item, on the screen, to a mail memo.

I'll try it again ...

Nov 21, 2013, 4:55 PM
47 Posts
What about RichTextItem?

Ann,

one thing I have done is changed from sending Mime to using RichTextItems for memo body.

var body:RichTextItem = doc.createRichTextItem("Body");

body.appendText("blah blah blah");

 

Nov 21, 2013, 5:23 PM
47 Posts
Use AppendRTItem

var body:RichTextItem = doc.createRichTextItem("Body");

var otherRTItem:RichTextItem = (RichTextItem) doc.getFirstItem("OtherRTItem");

body.appendRTItem( otherRTItem );

 

Nov 21, 2013, 5:44 PM
18 Posts
almost ...

so, I added this:

var body1:NotesRichTextItem = doc.getFirstItem("Body");

var body:NotesRichTextItem = memo.createRichTextItem("Body");

body.appendRTItem(body1);

and am getting the error:  NotesRichTextItem.appendRTItem(lotus.domino.local.item) not found, or illegal parameters

Nov 21, 2013, 7:26 PM
47 Posts
you need to cast the first one

var body1:NotesRichTextItem = doc.getFirstItem("Body");

needs to be:

var body1:NotesRichTextItem = (NotesRichTextItem) doc.getFirstItem("Body");

Nov 21, 2013, 7:50 PM
18 Posts
that throws an error before I even save it

I get a red x next to that line of code, with "Encountered "<IDENTIFIER>"doc"" at line .....

Was expecting one of:

","...

"?"...

"||"...

and so on

Nov 21, 2013, 8:06 PM
47 Posts
mixing Java / Javacript...sorry

JavaSCRIPT doesn't like casting.. and you are sure the first body1 item is RichText?  can you try getType() to verify?

Nov 21, 2013, 8:19 PM
18 Posts
using Javascript

And when I look at the document properties, my Body field is displaying as "MIME Part", even though I turned that property OFF on the underlying form.  I've removed the field from the xPage, and re-added it, since I changed the properties on the form. 

I have now tried

memo.copyItem(doc.getFirstItem("Body"));

and that doesn't throw an error, but the Body field is not copied either, IF there is an attachment in the field.  If there is only text in the field, that works fine.  Shouldn't "copyItem" copy any type of field??

Nov 21, 2013, 8:59 PM
47 Posts
Tested

I tried it with the following:

var body1:NotesRichTextItem = doc.getFirstItem("Body");
var body2:NotesRichTextItem = memo.createRichTextItem("Body");
body2.appendRTItem( body1 );

worked fine.  My body2 field had text and an attachment.  I received an email with the exact same text/attachment.

Nov 22, 2013, 1:00 PM
18 Posts
thanks! some questions

Thanks very much for testing that.  So, you did this from a button on an xPage?  What version of Domino are you running on your server?  And what data type is the Body field when it arrives in the email?

Nov 22, 2013, 1:16 PM
47 Posts
8.5.3 and..

Server and client code are both 8.5.3.    Javascript is indeed in a button on a XPage.  Delivered memo's BODY field is type RichText.  Hope that helps.

Nov 22, 2013, 1:24 PM
18 Posts
version may be part of the problem

My client is still 8.5.2 (I have no control over that).  My saved mail document has four Body "fields", but only the first one is getting emailed.  That shouldn't matter, I know Notes breaks fields up into pieces sometimes.  But the big difference is that the data type of the Body field is MIME Part.

What are the properties of your Body field on the form bound to your xPage?  Mine is editable Rich Text, display using HTML.

Nov 22, 2013, 1:44 PM
47 Posts
Didn't bind

This may be the issue.  I didn't use a datasource on the XPage.  I merely looked up another document in the DB used that doc's rich text field and then created a new memo, appended that RT Item and then sent.

Nov 22, 2013, 2:24 PM
18 Posts
interesting

I use "currentDocument" all over the place for hiding buttons, fields, lots of things.  This may be a stupid question, but without binding, how do you hide things?  I'll create a sample xPage without binding it and see what happens.

BTW, I tried "copyAllItems" and I do get a Rich Text body, but it's always blank.

Nov 22, 2013, 3:50 PM
47 Posts
Here's the full test

I have a view with 1 document.  That document was created with a form that has 1 rich text field.  The document has some text and an attachment.  So I get the document from the view, append the RT Item to my memo to be sent..

try {
var docView:NotesView = database.getView("All");
var doc:NotesDocument = docView.getFirstDocument();
var memo:NotesDocument = database.createDocument();
memo.replaceItemValue("Form", "Memo");
memo.replaceItemValue("SendTo","Michael Sava/Watson/IBM");
var body1:NotesRichTextItem = doc.getFirstItem("Body");
var body2:NotesRichTextItem = memo.createRichTextItem("Body");
body2.appendRTItem( body1 );
memo.send(false);
} catch(e) {
print(e);
}

Nov 22, 2013, 4:00 PM
18 Posts
I see ... got it working

You're using an existing document, where I'm using a newly created one, that the user is filling out.  Well, if all else fails, I can run an agent to email new replies after they're saved in the database.  That may be the easiest solution, actually.

I have created a LS agent that creates a new mail memo, and use appendRTItem there.  It fires when documents are created or modified, and checks for a flag that I've set in the button on the xPage.  The agent composes the email, sends it and resets the flag on the document so it isn't sent again.

Success!  Thanks again for all your help, it was invaluable.


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal