About Duffbert...

Duffbert's Random Musings is a blog where I talk about whatever happens to be running through my head at any given moment... I'm Thomas Duff, and you can find out more about me here...

Email Me!

Search This Site!

Custom Search

I'm published!

Co-author of the book IBM Lotus Sametime 8 Essentials: A User's Guide
SametimeBookCoverImage.jpg

Purchase on Amazon

Co-author of the book IBM Sametime 8.5.2 Administration Guide
SametimeAdminBookCoverImage.jpg

Purchase on Amazon

MiscLinks

Visitor Count...



View My Stats

« Book Review - Out of Control by Ben Young and Dr. Samuel Adams | Main| January/February's "You're SICK!" search hits... »

Show and Tell Thursday: Dynamic Rich Text web content using WebQueryOpen...

Category Show And Tell Thursday

Having not done a lot of web development in Domino until the last couple of years, I have to 'fess up...  I've never used WebQueryOpen/WebQuerySave agents, nor have I ever had to figure out the DocumentContext property.  That all changed today...

I have an application that gathers information on companies, and one of the features displays a printable web page with all the information about said company.  At the bottom of the page, I needed to have a section that displayed content for 0 to many articles related to the specified company.  Normally I'd just think computed text or embedded view, but the article information is rich text.  And instead of just linking them to the article, we need to display the text of the piece so that it will be printable along with the other company information.  I was afraid I had coded myself into a corner on this one until I started to play with WebQueryOpen.

Basically, I added a computed Rich Text field on the web form and then added a WebQueryOpen agent to build the value for that field before the document opens.  I wasn't sure that I could do that because of all the quirks of Rich Text, but it works like a charm.  Since the DocumentContext gives access to the document *before* it gets rendered to HTML, I guess the rich text that you add to the document isn't constrained by all those "front-end class" limitations you see in the Notes client.  Regardless, I was *thrilled* when I added the agent, refreshed the form, and got the dynamic rich content from a lookup view showing however many articles that are related to the company...  Not rocket science, but it made me feel good...  :)

Here's the agent I used in the WebQueryOpen event...

Sub Initialize
 
 'Build a dynamic Rich Text field for the webform based on contents from other documents.
 Dim session As New NotesSession
 Dim dbThis As NotesDatabase
 Dim docThis As NotesDocument
 Dim viewLookup As NotesView
 Dim dcLookup As NotesDocumentCollection
 Dim docLookup As NotesDocument
 Dim rtiArticleData As NotesRichTextItem
 Dim rtsArticleBold As NotesRichTextStyle
 Dim rtsArticlePlain As NotesRichTextStyle
 Dim varText As Variant
 Dim varConclusion As Variant
 
 Set dbThis = session.CurrentDatabase
 Set docThis = session.DocumentContext
 Set viewLookup = dbThis.GetView("vuwLookupArticles")
 
 'This is the rich text field we're building, along with some styling...
 Set rtiArticleData = New NotesRichTextItem(docThis, "altArticleData")
 Set rtsArticlePlain = session.CreateRichTextStyle()
 rtsArticlePlain.Bold = False
 rtsArticlePlain.NotesColor = COLOR_BLACK
 Set rtsArticleBold = session.CreateRichTextStyle()
 rtsArticleBold.Bold = True
 rtsArticleBold.NotesColor = COLOR_BLACK
 
 'Get the articles for this company from the lookup view
 Set dcLookup = viewLookup.GetAllDocumentsByKey(docThis.compCompany(0), True)
 
 'Either build the content or say there weren't any Articles for that timeframe.
 If dcLookup.Count = 0 Then
  Call rtiArticleData.AppendText("No articles within the last 90 days.")
 
 Else
 
  Set docLookup = dcLookup.GetFirstDocument
  Do While Not (docLookup Is Nothing)
   
   Call rtiArticleData.AppendStyle(rtsArticleBold)
   Call rtiArticleData.AppendText("Article: " + docLookup.altTitle(0) + _
   " (" + Format$(docLookup.commonCreateModifyDate(0), "mm/dd/yyyy") + ")")
   Call rtiArticleData.AddNewline(2)
   
   Call rtiArticleData.AppendStyle(rtsArticlePlain)
   Set varText = docLookup.GetFirstItem("altText")
   Call rtiArticleData.AppendRTItem(varText)
   Call rtiArticleData.AddNewline(2)
   
   Call rtiArticleData.AppendStyle(rtsArticleBold)
   Call rtiArticleData.AppendText("Conclusion")
   Call rtiArticleData.AddNewline(2)
   Call rtiArticleData.AppendStyle(rtsArticlePlain)
   Set varConclusion = docLookup.GetFirstItem("altConclusion")
   Call rtiArticleData.AppendRTItem(varConclusion)
   Call rtiArticleData.AddNewline(3)
   
   Set docLookup = dcLookup.GetNextDocument(docLookup)
  Loop
 
 End If
 
End Sub  

Comments

Gravatar Image1 - Rich text can be fun, but webqueryopen is bad if you want to have a scalable, responsive web site/application. I have been saying this for years and WQO was the exact reason my blog crashed and had to be taken down last week.

Gravatar Image2 - Thanks Tom, this method will certainly become a much used tool in my repertoire.

Gravatar Image3 - See, you have created a monster put there.

I am curious why you could not do a DBLookup to preformatted text or used AJAX to make the call, styling it with CSS when loaded?

Gravatar Image4 - The @DbLookup could have gotten hammered by the 64k limit, plus the users often put bullets and sections in their rich text. Couldn't have accommodated that in the lookup. And Ajax might have worked, except I'm not up to speed there, therefore it didn't come to mind.

Gravatar Image5 - Well, Chris... this is a business app I'm designing... Not a site designed to link to naked pictures of American Idol performers. :)

Gravatar Image6 - See. Rich text CAN be fun.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Want to support this blog or just say thanks?

When you shop Amazon, start your shopping experience here.

When you do that, all your purchases during that session earn me an affiliate commission via the Amazon Affiliate program. You don't have to buy the book I linked you to (although I wouldn't complain!). Simply use that as your starting point.

Thanks!

Thomas "Duffbert" Duff

Ads of Relevance...