Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, July 15, 2019

JavaScript regular expression trick

Working on a Netcool Impact implementation recently I ran across a feature of JavaScript regular expressions that really impressed me. I'll compare it to a somewhat similar feature/syntax in Perl.

If you need to test a string for a regular expression in Perl, you can do the following:

if ($mystring =~ /my_regular_expression/) ...

That will return true if $string contains the specified regular expression.

In JavaScript, you can invoke the test() method directly on the regular expression (including the leading and trailing "/") with one parameter, which is the string to test. Here's what the equivalent of the above looks like in JavaScript:

if (/my_regular_expression/.test(mystring)) ...

And to test if it doesn't match, the syntax is:

if (!/my_regular_expression/.test(mystring)) ...

That's it. I just thought it was pretty neat.

Wednesday, July 11, 2018

Processing JSON in automation scripts in IBM Control Desk 7.6


You may need to deal with JSON-formatted data in an automation script, and it can be a little tricky. I've written this post to provide the few little pointers to make it easier for you.


You can write automation scripts in Rhino JavaScript or Jython. While Jython is the most common language used for automation scripts, it turns out that JSON processing is MUCH easier in JavaScript. Specifically, in a JavaScript automation script, you have access to the popular object named JSON that will give you everything you need. Here's an example:

var jsonObject = JSON.parse(jsonString);

And that's it. You can now work with jsonObject as a JSON object as described in this reference material from w3schools:

As far as I know, this will work in both WebSphere and WebLogic application servers. One possible caveat is that the JavaScript engine is changing from JDK 7 to JDK 8. Here's more information on that:

Jython in WebSphere

For Maximo/ICD automation scripts, Jython is by far the most popular language. It's also more thoroughly documented and, IMO, easier to work with in this context. However, JSON parsing has a couple of caveats. Specifically, the Jython interpreter in ICD 7.6 is version 2.5.2, which doesn't have a built-in JSON parser (one was added in Jython version 2.6). However, we're still in luck because WebSphere actually includes a JAR file that provides JSON processing. The specific class that you need to import is :

from import JSONObject
my_json = JSONObject.parse(my_filebody)

And from there, you can deal with my_json appropriately according to the JavaDoc here:

Jython in WebLogic

Admittedly, I haven't tested this one. I've tested the above two, and from my research, I believe this will work. Specifically, these two links give the necessary information:

If you find that it doesn't work, please ping me and I'll help you get it to work then update this entry as necessary.

With that in mind, you just need to import the appropriate classes in your automation script:

from javax.json import Json
from javax.json import JsonObject

And there you go.

Sunday, July 29, 2012

Extending TSAM using Eclipse

If you have been using Tivoli Service Automation Manager (TSAM) for Cloud provisioning, the usual way for service offering customization is to write Javascript and HTMLs directly on TSAM server.   With TSAM 7.2.2, there is an Eclipse based project available for self service offering customization.   Using this Eclipse project, you can perform Javascript customization right from your Eclipse IDE.  This artcile provides a high-level technical overview of this process.

To setup the Eclipse development environment,  you need to download/setup Eclipse first.  Even thought the latest versions of Eclipse should work, according to documentation, the Eclipse projects were tested with Helios (3.6) version and it is safe to use either Helios or Galileo versions.  Once Eclipse is setup, you simply have to download the project zip from TSAM install images located under TSAMBASE7300/samples/UI directory and import two Eclipse projects viz, custom_web and custom_web_build into Eclipse using Eclipse Import wizard. 

The custom_web project is used to make any javascript changes.  The custom_web_build project contains several ANT tasks that can be used to perform deployment to TSAM Server.   Connection to TSAM server is managed through SSH and you can specify the authentication parameters in SSH authentication can use either SSH keys or password.

For testing you can use the quickdeploy ANT task that rebuilds the custom_web.war application as you publish the changes.  You can also backout the changes using undeploy task but that basically removes the custom_web.war from the TSAM server removing all custom changes.   For production deployments, you will have to rebuild the maximo.ear file using command.

You can find more information about this TSAM customization in TSAM 7.2.2 Extensibility Guide available at the following location.

Hope this helps you get started with TSAM customization. If you have any questions, please feel free to post it it in the comments.