How to export Rich Text fields to HTML from Notes using LotusScript?

I am working on a data migration task where I need to export a somewhat large Lotus Notes application to a blogging platform. My first task was to export articles from Lotus Notes to CSV files.

I created an agent in LotusScript to export data to CSV files. I am using a modified version of this IBM DeveloperWorks post . And that basically does the job. But the content of the Rich Text field is devoid of any formatting. And this is not what I want, I want the Rich Text field to display as HTML.

The documentation for the GetItemValue method explicitly indicates that the text is displayed as plain text. So I started researching something to get HTML. I found the NotesMIMEEntity class and some sample code in an IBM article How to Access HTML in a Text Box Using LotusScript .

But for the method described in this article, to work in the Rich Text field, there must be the property "Store content as HTML and MIME". And this does not apply to my Lotus Notes database. I tried setting the property to the appropriate fields, but that did not help.

Can I use NotesMIMEEntity and set the property "Save content as HTML and MIME" after adding content to export the field displayed as HTML?

Or what are my options for exporting Notes Rich Text fields in HTML format?

Bonus information: I am using IBM Lotus Domino Designer version 8.5

+4
source share
9 answers

I would suggest looking at the Richas LSX Midas ( http://www.geniisoft.com/showcase.nsf/MidasLSX )

I did not use it personally, but I remember that they were many years ago, and this is the best option for working with Rich Text. I bet it saves you a lot of headaches.

As for the NotesMIMEEntity class, I don't believe that there is a way to convert RichText to MIME, just MIME to RichText (or save MIME in a document for email purposes).

+4
source

There is a rather unknown command that does exactly what you want: get the URL using the OpenField command.

An example that converts only the Body field:

http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField 
+8
source

If you are upgrading to Notes Domino 8.5.1, you can use the new ConvertToMIME method of the ConvertToMIME class. See docs . This should do what you want.

Alternatively, the easiest way to get a Domino server for RichText rendering is to actually get it through the URL. Set up a simple form that only has a RichText field, and then use your favorite HTTP api to pull the page. Then it should be pretty easy to pull out the body.

+5
source

Here's how I did it using the OpenField command, see D.Bugger post above

 Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String Dim obj Set obj = CreateObject("Microsoft.XMLHTTP") obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", "" obj.send("") Dim html As String html = Trim$(obj.responseText) GetHtmlFromField = html End Function 
+4
source

You can use the NotesDXLExporter class to export Rich Text and use XSLT to convert the output to what you need.

+2
source

I know that you mentioned the use of LotusScript, but if you do not mind writing a small Java agent (in the Notes client), this can be done quite easily - and there is no need to change the existing form design.

The basic idea is for your Java code to open a specific document through the localhost HTTP request (which is simple in Java) and for your code to capture this html output and save it back to that document. You basically let the Domino rendering engine do the heavy lifting.

Would you like to do this:

  • Create a form containing only the rich text field you want to convert and with the HTML content type
  • Create a view with a selection formula for all the documents you want to convert and a form formula that calculates the new form
  • Create a Java-agent who simply watch your presentation and for each document gets his docid, opens the URL-address in the form http: //SERVER/your_database_path.nsf/NEW_VIEW/docid OpenDocument? , Captures HTTP-response and saves it.

I put some sample code in a similar SO post here:

How to convert text and text fields to a document in html using lotusscript?

+2
source

Keep it simple.

Change the BODY field to save content as HTML and MIME

Open the document in editmode. Save. To close.

Now you can use NotesMIMEEntity to get what you need from the script.

+2
source

Casper's recommendation above works well, but make sure the ACL is such as to allow anonymous access, otherwise your HTML will be HTML from your login form.

0
source

If you don’t need to get Richtext from elements specially, you can use OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/ https: // www. ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html

OpenDocument also lets you expand partitions (I'm not sure what OpenField does)

Syntax: http: // Host / Database / View / DocumentUniversalID? OpenDocument

But be sure to include the charset parameter - Japanese documents cannot be read without specifying utf-8 as the encoding.

Here is the method I use that takes NotesDocument and returns the HTML for the document as a string.

  private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null) { var server = doc.ParentDatabase.Server.Split('/')[0]; var dbPath = doc.ParentDatabase.FilePath; string viewName = "0"; string documentId = doc.UniversalID.ToUpper(); var ub = new UriBuilder(); ub.Host = server; ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId; if (string.IsNullOrEmpty(sectionList)) { ub.Query = "OpenDocument&charset=utf-8"; } else { ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList; } var url = ub.ToString(); var req = HttpWebRequest.CreateHttp(url); try { var resp = req.GetResponse(); string respText = null; using (var sr = new StreamReader(resp.GetResponseStream())) { respText = sr.ReadToEnd(); } return respText; } catch (WebException ex) { return ""; } } 
0
source

All Articles