Trap in BPM new event handler editor

Early 2017 cumulative fix for IBM BPM 8.5.7 brought new section in properties for coach views configuration – events tab. This looks like a wink at SPARK toolkit being integrated with BPM product. SPARK introduced nice concept of configuration options storing Javascript code created outside of coach views, events code as one of them. Configuration option was limited to one line string however. New editor in events tab is multi-line with code coloring. It has also nasty trap for young players though, let’s take a look.

New event editor is multiline. Long awaited enhancement for those who place enough complicated inline code. By default single event field height is enough to place 3 lines of code, but extra mini-button with chevron allows to open wide text area.

Multiline editor combined with code coloring invites developer to enter full fledged code, comments included. So I placed my handling code and commented it like this:


Did it work well? Nope, the code was not run at all! It took me few runs and checks to realize that event handler is interpreted as single line expression even though code coloring suggest it is multiline. Hey IBM, thank you very much again!

SPARK handlers run as JavaScript functions created by new Function(expression) with expression passed from handler editor. And obviously that expression does not have newlines inserted correctly. See following browser console snippets with missing newlines (left) and correct newline (right). Leftside return statement becomes part of single line comment same as in BPM event handler editor:


The only safe way to document code in even handlers is to use block comments like this:


EDIT: Few days later I discovered another trap in the same place. This time I was processing strings with new line character inside e.g. having something like msg1 + “\n” + msg2. Once again editor suggested I deal with correct JS code but runtime thrown “Invalid or unexpected token“. Keeping in mind that everything inside is just a string to be evaluated, I suspected that special characters must be escaped. So I have added backslash like this msg1 + “\\n” + msg2 and this time event handler worked as a charm. IBM proven technology sounds more and more sarcastic.

This entry was posted in Software and tagged . Bookmark the permalink.

1 Response to Trap in BPM new event handler editor

  1. Anonymous says:

    i have no idea

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.