IBM Support

Best practice for scripting

Technical Blog Post


Abstract

Best practice for scripting

Body

Solution developers who used the script adaptor or script action would like to be able to debug the scripts.

Because the scripts are embedding inside the page HTML template and evaluated at runtime, the browser developer tools (e.g. firebug) can’t show them as as normal js file. So you can’t add break point to the scripts. Usually, you have to add console log between the lines of scripts for debug purpose. If you need to update the scripts, you have to open the solution in the Case Builder, update the scripts inside the page designer, and redeploy the solution.

You would like to see the best practice for improving the user experience of the script adapter. With it, as a solution developer, you can

1.     Debug the scripts.

2.     Update the scripts at runtime without the necessary to go back to case builder and redeploy the solution.

3.     Share the script pieces between script adaptors.

The basic idea is simple. You just need to consolidate the scripts into an IBM Navigator Plugin, and let script adaptor call them.

We demonstrate the approach with a sample. The scenario is that, in the cases page, customizing the case search payload by adding additional search criteria of a Boolean attribute must equal true.

Firstly, you need an IBM Content Navigator Plugin, having the scripts consolidate into a js file. For each piece of scripts, having a function enclose it, and expose it through a global object (e.g. icmscripts). The enclosing function has four parameters, the first one is the event payload, the second and the third one are the solution and role context, the last one is the script adaptor page widget instance for the script to take control of the publishing/broadcasting events itself.

image

       Secondly, you need to register Plugin to the IBM Content Navigator. In your development environment, you should register it with the class file mode. With the class file mode, it makes easy for you to update the script file when do debugging. After build the plugin jar file, in the development environment, you should decompress the jar file to a temporary folder, and register the folder as plugin.

 image

     At last, you need to edit the cases page. Opening the solution in the case builder, in the cases page, disabling the broadcasting of ‘icm.SearchCases’ event on the case search page widget, then add a script adaptor, wiring its ‘icm.ReceiveEvent’ to the case search’s ‘icm.SearchCases’ event, and wring its ‘icm.SendEventPayload’ to the case list’s ‘icm.SearchCases’ event.

image

In the script adaptor configuration, you input a line to call the function enclosing the script exposed from the IBM Navigator Plugin with the necessary parameters pass in.

image

 

In your development environment, when debugging the script, you can find the script js file from firebug or other development tool. You can break points and do debugging works. If you need to update the scripts, you just need to update the script js in the folder of the uncompressed IBM Content Navigator Plugin jar, then clear the cache and refresh the web browser.

        image

Sample links: 

- Script Plugin Project 

Please unzip it, and import to eclipse, run ant build for generating the plugin.jar

scriptPlugin.project.zip

- Test Script Solution 

Please import it to your IBM Case Manager using the IBM Case Manager Admin Client.

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

ibm11281370