IBM Support

Best practices for debugging and organizing scripting code in Case Manager

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.

image

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.

image

Finally, edit the Cases page as follows:

  1. Open the solution in Case Builder.
  2. Edit the Cases page and edit the Case Search page widget settings.
  3. Disable the broadcasting of ‘icm.SearchCases’ event.
  4. Add a Script Adapter widget to the page
  5. Wire the Script Adapter's ‘icm.ReceiveEvent’ to the Case search widget's ‘icm.SearchCases’ event.
  6. Wire the Script Adapter's ‘icm.SendEventPayload’ to the Case List widget's ‘icm.SearchCases’ event.

image

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.

image

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

  1. Update the script js file in the folder of the uncompressed IBM Content Navigator Plug-in JAR
  2. Clear your browser cache
  3. Reload the page.

    image

    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.

    scriptPlugin.project.zip

    Test Script Solution

    Use the IBM Case Manager Admin Client to import the test script.

    TestScriptPlugin_solution.zip

    (Tested with IBM Case Manager 5.2.0.1)

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSCTJ4","label":"IBM Case Manager"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

UID

ibm11280662