Gotcha, Creating Dynamic Script Blocks Using SSJS

For our iPhora applications we only use one XPage and dynamically create the content that appears.  We do this by storing the dynamic content in Notes Rich Text fields and using SSJS to read and generate the HTML/JavaScript during runtime. 

Since we are moving to an single page MVC model, we were adding a few addition xp:scriptBlock to generate the initial loader and pulling the information from a NotesRichText field.  We were using doc.getFirstValueString('richtextfield') to pull and create the script. No problem until, we had a JavaScript object declaration that was longer than 72 odd characters.

Unfortunately, there is an issue with Notes Rich Text fields that we encountered in the past using LotusScript that I forgot all about.  When you read a Notes Rich Text field it will automatically add a carriage return after 72 characters and this can drive you crazy. If the carriage return occurs between a JavaScript object declaration then you will get an JavaScript error.

To resolve this you need to switch to doc.getFirstItem("richtextfield").getUnformattedText() to read it.  The automatic carriage return that Domino/Notes pulls in is filtered out, but the carriage returns that you put in remains.


NotesSensei said…
There are options:
- you could go an store your content into a MIME entry and read that -> the content could have any form.
- you could use an attachment you generated
- use a bean with a cache instead of a pure script block. There you could do the filtering

Popular posts from this blog

The iPhora Journey - Part I - Reimagining Domino

Creating Composite Applications for Classic Lotus Notes Clients – Part 2

The iPhora Journey - Part 5 - Dammit Jim, I'm a LotusScripter not a JavaScripter