Invoke channel scripts

Like publish channels, invoke channels are used for outbound invocation from IBM® Maximo® Manage. The only difference is that the publish channel is one-way, request only, and the invoke channel is two-way, request and response. Since there is a request and response, there are two sets of exits: one set for request and one set for response.

The following table lists the script points for the invoke channel:
Table 1. Script points for the invoke channel
Script point Purpose
Outbound external exit This script point is for preparing the outbound call. This script point can be used to prepare the request data or the request URL.
Outbound before user exit Similar to the outbound external exit, this script point can be used for preparing the data or the request endpoint data. Use this script point if there is already an external exit and you want to customize some data before it reaches that exit.
Outbound after user exit Similar to the outbound external exit, this script point can be used for preparing the data or the request endpoint data.
Inbound external exit This script point is for handling the response of the invocation, if there is a response. Like any inbound external exit, this script point should be used to map the response data to internal format.
Inbound before user exit Similar to the inbound external exit, this script point can be used for mapping the inbound data.
Inbound after user exit Similar to the inbound external exit, this script point can be used for mapping the inbound data.

All the outbound script points have the same variables as publish channel scripts. All the inbound script points have the same variables as enterprise service scripts.

The following example shows how to set the city and state in the Addresses tab of the Organizations application when the zip code is entered. Assume you have the following external REST API:

GET {zip to city uri}?zips={zip code}

The response is JSON that returns the city and state for the zip code. You want to invoke that API when the user enters the zip code and then tabs out. To do this, create an object structure for the address Maximo business object (MBO), named, for example, MXADDRESS. Next, set up an invoke channel with an HTTP endpoint that has the URL set to the {zip to city uri}. Set the zip query parameter dynamically in the exit scripts. Select the Process response check box and set the request and response object structure to MXADDRESS.

Next, create the external exit scripts for both the request and response handling. Use the Create > Script for Integration menu option from the Automation Scripts application to create the request and response exits for the invoke channel. For both exits, choose the external exit option. The request (INVOKE.ZIPCHANNEL.EXTEXIT.OUT) exit in Python is shown in the following example.
from java.util import HashMap
from psdi.iface.router import HTTPHandler
from psdi.iface.mic import IntegrationContext
from psdi.iface.mic import MetaDataProperties
epProps = HashMap()
urlProps = HashMap()
zip = irData.getCurrentData("ADDRESS4");
urlProps.put("zips",zip)
epProps.put(HTTPHandler.HTTPGET_URLPROPS,urlProps)
The response (INVOKE.ZIPCHANNEL.EXTEXIT.IN) exit in JavaScript is shown in the following example.
var resp = JSON.parse(erData.getDataAsString());
var irData = new StructureData(messageType, osName, userInfo.getLangCode(), 1, false, true);
irData.setCurrentData("ADDRESS3", resp.zips[0].state);
irData.setCurrentData("ADDRESS2", resp.zips[0].city);
The response JSON might look like the following example.
{
  "zips":[
      {
        "state":"MyState",
        "city":"MyCity"
        ….
      }
  ]
}
You can optimize this script for the given use case. For example, you can directly set the JSON data to the MBO, something that you can do only in the case of Invoke Channels.
IntegrationContext = Java.type("psdi.iface.mic.IntegrationContext");
var resp = JSON.parse(erData.getDataAsString());
var mbo = IntegrationContext.getCurrentContext().getProperty("targetobject");
mbo.setValue("address3",resp.zips[0].state);
mbo.setValue("address2",resp.zips[0].city);
service.raiseSkipTransaction();

You got the MBO from the IntegrationContext targetobject property, which stores the reference of the MBO to which you are going to set the JSON response. Setting the response can be done by Maximo Integration Framework (MIF) using the irData. In the following example, you do not need to create the irData. You use the response JSON object to get the city and state and set it directly to the MBO. Then you can skip the rest of MIF processing by asking the service object to skip the transaction. You can use this in other forms of inbound exits, like the user exit and the external exit for enterprise services. Set the data to the MBOs that you want and then skip the rest of the MIF processing. Also, this IntegrationContext targetobject property is available only for exits in InvokeChannel.

Write an Attribute LaunchPoint script action event for the Address4 attribute, zip code attribute in Address object, to invoke this channel when the zip code value is set.
service.invokeChannel("zipchannel")

You use the service variable to do this call. This calls the channel, which in turn goes through the request and response exits.