Category: Integration (Page 3 of 5)

String Concatenation in WebMethods

Manipulating string is probably the most frequent operation we need to do when transforming data. Thus, I’d like to talk a bit about string concatenation in WebMethods. The most basic way to add two strings is to use the pub.string.concat service in the WmPublic package as shown below:

Image 01. pub.string.concat service

However, this approach is way too limited. For example, to combine a Unique ID string which consists of a Prefix, an auto ID number, a Suffix with separator in between such as: WO-10012-CM, we’ll need to use at minimum 4 lines of code, and a number of temporary variables. That’s crazy.

An alternative approach is to use variables substitution when assigning values to a variable as shown below. In this case, we can build a new string from an unlimited number of variables in just one line of code.

Image 02. using variables substitution

This approach doesn’t work if one of the input variables can have a Null value. In that case, it will give us an unwanted result as shown below:

Image 03. Bad result when input is Null

With Tundra library, we have a much more flexible tundra.string.concatenate service. It allows us to add unlimited number of strings in one line, and at the same time, have some other capabilities such as adding separator.

Image 04. Use tundra.string.concatenate

In the example above, I can achieve the same result in one line of code, and the tundra service is smart enough not to add the second separator when the $suffix variable is Null.

However, beware of the annoying bug with WebMethods that it doesn’t have ability to set the order of input variables. Thus, when you make an update to one input, for example, in the example below, I changed the input variable str2 to map it to a different variable, it will move to the bottom of the list, and thus, messed up the final output.

Image 05. Last updated variable is moved to the bottom

A workaround is to update the other variables manually to correct the order. But from my experience, anything having more than 3 inputs will be a maintenance nightmare.

Image 06. A “quick” update messed up the order of concatenation

The more robust approach is to write our own concatenate service as part of a common service package. It can take a bit of time, but if we have a big project, it’s worth the effort in building some common service library to be reused across the entire environment. Ten minutes spending on building this service can save the whole team countless number of hours in development and maintenance.

Edit: After reading this post, Lachlan Dowding, Tundra library’s author, told me we can use String List to workaround the WebMethods’s bug on changing the order of input strings when using the Tundra’s concatenate.

Implement If-Then-Else Logic in WebMethods

Conditional Logic is the most important building block of any software development tool. WebMethods is not a programming language, but since we use it to build integration interface, which is also software, it means we are also programming with it. Writing a simple “If-Then-Else” condition in WebMethod is way too verbose to me though. The official tutorial on SoftwareAG teaches us to implement an if-then-else logic using the Branch, Sequence, and Map nodes as depicted in the sample below:

As we can see, one simple If-Then-Else condition will require at least 5 lines to achieve. A more complex Case condition with multiple branches can take up half of a screen’s real estate. This makes the code harder to read.

My preferred alternative approach is to use the “Copy Condition” when mapping variables as shown below:

If the condition specified in this “Copy Condition” is True, the value will be mapped from the left-side variable to the right-side variable. In this case, value of the $valuelist/Approved variable will be mapped to the $output variable if condition $var1 = ‘A’ is True.

To achieve the default (Else) branch, we use the NOT (!) operator such as: 

! ($var1 = ‘A’ OR $var1 = ‘W’ OR $var1 = ‘C’)

By doing this, no matter how many conditions we have, we can fit everything in one line.

 

 

Send email from automation script

Simple stuff but I got a few people asked me this same question, so here is how to create an automation script to send email from Maximo:

1 – Create a Communication Template:

  • Template ID: MY_COMM_TEMPLATE
  • Description: Test Communication Template
  • Applies To: ASSET
  • Send From: <your_email@address> (Note: to make this work, you must have setup smtp and able to send email from Maximo first
  • Subject and message: as shown below
  • In the “Recipients” tab, add an Email recipient pointing to your own email:

2 – Create an Automation Script

Create an autoscript with Object Launch Point on the “ASSET” object, on the SAVE (Update) event, choose Language = Python and copy/paste the following sample script:

3 – Test sending email

Open an Asset then change its status to INACTIVE, you should receive an notification in your email inbox:

Process Inbound Twilio SMS message in Maximo

In my previous post, I provided some demos on how we can process inbound text messages to create SR and route Workflow. There are a few people on LinkedIn asked me how to do it. I also like to explore the option of integrating Maximo with Twilio directly without the need for AppConnect. With Maximo 7.6, we can create a simple API using automation script. To prove the concept, the video demonstrates how we can create a simple API with automation script and direct Twilio HTTP requests to Maximo:


Below is the source code for the script in the video:

In this case, for the sake of simplicity, I only include the bare minimum components to make it works. You will probably want to write some scripts to automatically populate the “Reported By” person based on source phone number and populate other details like location/asset number based on the content of the incoming message. Also, it would be nice to respond with a text message for confirmation and provide the users with the new SR number.

With this method, we’ll need Maximo to be accessible from the Internet, it’s is not a problem for a cloud-based system. But if you have an onpremise system, you’ll need to configure port-forwarding to make Maximo accessible from the Internet. For development, since my ADSL router does not support port-forwarding, I used a tool called ‘ngrok’ to forward access of my local Maximo to the web via ngrok.io

The Scripted API is a new feature in Maximo 7.6. Thus this approach won’t work if you have an older Maximo version. It that case, probably using App Connect is an easier option. With App Connect, I used it for two functions:

  • Act as an API gateway to route Twilio request to a local server
  • Quickly transform HTTP request to REST/JSON request which Maximo can easily consume

App Connect is just a fancy name for a newer version of IBM Integration Bus (which IBM now call it App Connect Enterprise) and a bunch of new cloud-enabling features. So you’ll need some basic understanding of IIB in order to set it up. For connecting App Connect (the cloud component) and local Integration server, I followed the tutorial here: link

Interacting with Maximo via SMS with Twilio

Voice call and SMS are being used as a user interaction interface in many systems and services provided by large organizations. However, in the past, this integration is quite complex and expensive, and I never had a chance to play around with it. Recently, I posted an article on how we can easily configure Maximo to send SMS notifications. This is made easy and free (for developers) by using Twilio.

Sending inbound commands to a system from Twilio is more complex as it requires setting up a Web Server and writing code to parse HTTP POST requests, then forward the message to an onpremise Maximo system. With App Connect, it becomes easy (and free for developers) to set up an API gateway on the cloud and route messages to a system hosted in-house. I decided to give it a crack by imagining two easy use cases as follows:

  • Field workers send a text message to Maximo to create a new Work Request, or to report a Defect. This could be useful to quickly register an action item without having a smart device or 3G connection. Below is a quick demo of this scenario:
  • A user approves a workflow request by sending a SMS command. This could be useful for supervisors or managers who are always travelling or in meetings and don’t check email often. In many cases, the managers are often given a heads-up call, approving workflow is just a formality to keep record. With such scenarios, just reading the title of the request in a text message will be enough for the approver to say Yes or No, this approach could speed up the approval process. Below is a quick demo for this use case:

There are many other use cases we can implement SMS, MMS, or Voice command to add value. I can quickly think of a few such as

  • Field workers sending an acknowledgement of new work order assignment and confirmation of  scheduled start time entered by planners
  • Driver sending in telemetry data (fuel level, mileage etc.) or technician sending in asset meter data
  • Workers updating actual labour hours to work orders.
  • And whatever simple yet important data you can think of here

For the technical consultants who are interested in App Connect, the image below is how I integrated Twilio with Maximo via App Connect:

This may look a bit complex, but in fact, it is quite simple. The whole process to set up AppConnect, hook up with Twilio and Maximo takes less than 15 minutes. For Maximo on the cloud, I guess we can configure Maximo to hook up with Twilio directly. But I don’t have access to a cloud Maximo environment which I can mess with. So perhaps, that can be saved for a future article.

Send SMS Notification from Maximo using Twilio

Email or SMS Notification?

Occassionally, someone would ask me if we can configure Maximo to send notifications via SMS. With Maximo, the answer to such questions is always Yes. However, with this one, it will cost some money, very cheap though.

Since it is not free, I would say for most Maximo notification scenarios, the user would be ok with email notification which is free. However, there are certain scenarios where SMS notifications can add value such as:

  • Notify a field worker when a new high priority Work Order is assigned to him/her
  • Notify an asset owner when the asset deviates from the normal operating parameter range or when downtime is reported
  • Notify Maximo admin when there are repeated login attempts from an uncommon IP address or when there is a major problem tracked by the Escalation app.

In the section below, I provide the detailed steps on how to set up a trial Twilio account and send notifications from Maximo

A. Setup a Twilio trial account

With your trial account, Twilio will give you a small initial balance to buy a phone number and use the service. I got $15, and it will cost me $6 to buy a phone number, and 5 cents to send a text message.

  1. Create a trial account on Twilio.com: you’ll have to use your real mobile phone number to verify the account.
  2. Login using your trial account, go to Console, then create a new Project. Select “Products”, then choose “Programmable SMS”. Give your project a name, for example: “Maximo”. Then skip the rest of the steps to create the project
  3. On the left menu, click on the icon with the title “Programmable SMS”. In this menu, open the “SMS” submenu, open the “Messaging Services” page, then click on “Create new Messaging Service
  4. Give the messaging service a name, such as “MaximoNotification”. For use case, choose “Notifications, Outbound Only”. Then click on Create
  5. After the messaging service is created, open it. On the left menu, click on Number to open it, then click on “Buy a Number” to purchase a telephone number. On the pop-up, select your country code, then click on “Search”. It will give you a list of numbers to choose from
  6. Choose a number with SMS capability, and click on Buy. Depends on the country you live in, you may have to enter some details for your new number. I’m in Australia, so I have to enter my address.
  7. After purchasing a number, you are ready to send SMS messages from your Twilio account.
    Please note: with Trial account, it can only send SMS messages to a Verified Number. Your mobile number which you entered when registering is automatically added to this list. So you will be able to send SMS to that number. But if you like to send SMS to a different number, you’ll have to add it to the ‘Verified Caller ID’ list first.
  8. Go to “Console Dashboard”, open the “Settings” sub-menu, then open “General” page to take note of your Account SID, and Authentication Token. You will need it to send an SMS from Maximo.

B. Configure Maximo to send REST requests to Twilio

There are different ways to set this up depending on your requirement. In this example, I’ll create an ‘Action’ automation script, and send a REST request using Apache HTTPClient library. Action auto script can be used with Workflows or Escalation. In this example, I’ll send out an SMS when the workflow is initiated on the Service Request application.

The setup steps are as follows:

  1. Go to Automation Script application, create an ‘Action launch point’ automation script. Give the launch point a name, for example: “SENDSMS”. Set the action name as “SENDSMS” too. Set “SR” as the main object. Select “Jython” for script language. For the script, copy/paste the example code below to the “Source Code”
  2. With the code above, replace {YOUR_ACCOUNT_SID}, {YOUR_AUTH_TOKEN}, {YOUR_PURCHASED_PHONE_NUMBER} with actual details of your Twilio account. For testing purposes, replace {RECIPIENT_PHONE_NUMBER} with your phone number. Later on, once it works, you can replace it with a variable retrieved from your record using mbo.getString()
  3. Create a new workflow “SEND_SMS” for the SR object, connect the Start and Stop node with one line. And set the line to use ‘SENDSMS’ action. After that, Enable and Activate the Workflow. And remember to Add Workflow to SR application using the Select Action menu if you haven’t done so.
  4. Open an SR record, then click on the route button to initiate the “SEND_SMS” workflow
  5. After clicking on the Route workflow button, you should be able to receive an SMS message on your phone:

Source Code:

In a later post, I’ll talk about integrating Twilio with Maximo to create new Service Requests via SMS. For now, good luck with spamming your end-users with endless work requests 🙂

« Older posts Newer posts »