Technical Blog Post
Abstract
Best practices for debugging and organizing scripting code in Case Manager
Body
Issue: Solution developers who use the Script Adapter widget or the Script action need to debug their scripts.
Because the scripts are embedded inside the HTML template corresponding to the page and evaluated at runtime, browser-specific developer tools, such as Firebug, do not display the script as a normal JavaScript (js) file. Therefore, adding breakpoints to the scripts is not useful. Instead, to debug your scripts, usually, you have to add console.log statements between the lines of the scripts. Also, if you need to update the scripts, you have to open the solution in Case Builder, update the scripts inside the page designer, and then redeploy the solution.
As a solution developer, you would prefer to do the following:
- Debug the scripts easily.
- Update the scripts at runtime without it being necessary to go back to Case Builder and redeploy the solution.
- Share the scriptlets between Script Adapter instances.
In this article, we demonstrate a simple approach for consolidating the scripts into an IBM Content Navigator Plug-in, which the Script Adapter can then call. A sample plug-in is attached for your reference.
Scenario
In the cases page customize the case search payload by adding an additional search criteria of a Boolean attribute must equal true.
First, create an IBM Content Navigator Plug-in which has the scripts consolidated into a single JavaScript (js) file. For each piece of script, we recommend creating a function and exposing the function via a global object as shown in the following figure. The enclosing function has four parameters, the first one is the event payload, the second and the third are the solution and role context, the last parameter is the Script Adapter page widget instance for the script to take control of the publishing/broadcasting events.
Second, register the plug-in in IBM Content Navigator. In your development environment, register the plug-in with the class file mode. Using the class file mode, makes it easy to update the script file when debugging the code. After building the plug-in JAR file in the development environment, decompress the JAR file to a temporary folder, and register the folder as a plug-in.
Finally, edit the Cases page as follows:
- Open the solution in Case Builder.
- Edit the Cases page and edit the Case Search page widget settings.
- Disable the broadcasting of ‘icm.SearchCases’ event.
- Add a Script Adapter widget to the page
- Wire the Script Adapter's ‘icm.ReceiveEvent’ to the Case search widget's ‘icm.SearchCases’ event.
- Wire the Script Adapter's ‘icm.SendEventPayload’ to the Case List widget's ‘icm.SearchCases’ event.
In the Script Adapter configuration, input the following line of code to call the function, enclosing the script exposed from the IBM Navigator Plug-in with the necessary parameters passed in.
In your development environment, when debugging the script, you can find the Script js file in Firebug or other browser development tools. You can then add breakpoints and do your debugging. If you need to update the scripts, simply
- Update the script js file in the folder of the uncompressed IBM Content Navigator Plug-in JAR
- Clear your browser cache
- Reload the page.
Sample links
Script Plug-in Project
Unzip the script plug-in project, and import the project into Eclipse, then run an ant build to generate the plug-in.jar.
Test Script Solution
Use the IBM Case Manager Admin Client to import the test script.
(Tested with IBM Case Manager 5.2.0.1)
UID
ibm11280662