Service object
The service object is an implicit object available in all scripts. For most of the script
points it is called service
. The Maximo®
Integration Framework (MIF) object structure scripts do not directly refer to this variable as
service
. Instead, they refer to it as ctx
, which is an extended
version of the service object.
The service
object helps to simplify some common tasks for an automation script.
For example, tasks like throwing an error, adding a warning, or starting workflows, MIF invoke
channels, logging, HTTP calls and so on are simplified by using the service
variable. For example, if you want to produce real-time errors, rather than setting the errorkey and
errorgrp variables, use the service.error(grp,key) or service.error(grp,key,params) APIs to achieve
the same result. It is also used to start library scripts. There are also examples on how to invoke
a MIF invoke channel to integrate to some REST APIs by using the service.invokeChannel(channelname)
API. The service
object supports the following built-in functions.
Function | Request | Response | Description |
---|---|---|---|
jsonToString | com.ibm.json.java.JSONObject | String | Used for converting a JSON object to a string. |
jsonarrayToString | com.ibm.json.java.JSONArray | String | Used for converting a JSON array to a string. |
tojsonarray | String | com.ibm.json.java.JSONArray | Converts a string to a JSON array. |
tojsonobject | String | com.ibm.json.java.JSONObject | Converts a string to a JSON object. |
Function | Request | Response | Description |
---|---|---|---|
closeDialog | NA | Void | Closes a dialog from an application that is not Graphite-based when the script is run in
context of an action launch point. A sample invocation is
service.closeDialog() |
openURL | String (URL to open), Boolean (whether to open in a new window) | Void | Opens a URL specified in the input string parameter. A sample invocation is
service.openURL("weather.com", False) |
Function | Request | Response | Description |
---|---|---|---|
httpget | String | String | Invokes HTTP GET on the specified URL input string parameter and returns the response as a
string. Do not use this function if the GET response type is anything but a string or null. A sample
usage is as follows:
|
httppost | String (URL), String (POST data) | String | Invokes HTTP POST on the specified URL input string parameter with POST data as a string and returns the response as a string. Do not use this function if the POST response type is anything but a string or null. |
httpget | String (URL),String (user), String (password) | String | Invokes HTTP GET on the specified URL input string parameter for BASIC authentication user and password. Returns the response as a string. Do not use this if the GET response type is anything but a string or null. |
httppost | String (URL),String (user),String (password), String (POST data) | String | Invokes HTTP POST on the specified URL input string parameter for BASIC authentication user and password with POST data as a string and returns the response as a string. Do not use this function if the POST response type is anything but a string or null. |
httppostasjson | String (URL),String (user),String (password), com.ibm.json.java.JSONArtifact (POST Data) | com.ibm.json.java.JSONArtifact | Invokes HTTP POST on the specified URL input string parameter for BASIC authentication user and password with POST data as a byte[]. Returns the response as JSON. Do not use this function if the response type is anything but JSON or null. |
httppostasbytes | String (URL),String (user),String (password), byte[] (POST data) | byte[] | Invokes HTTP POST on the specified URL input string parameter for BASIC authentication user and password with POST data as a byte[] and returns the response as a byte[] or null. |
httpgetasjson | String (url),String (user),String (headers), String (password) | com.ibm.json.java.JSONArtifact | Invokes HTTP GET on the specified URL input string parameter for BASIC authentication user
and password. The format for headers being
header1:val1,header2:val2 . Returns the response as JSON. Do not use this if the
response type would be anything but JSON or null. |
httpgetasbytes | String (url),String (user),String (password) | byte[] | Invokes HTTP GET on the specified URL input string parameter for BASIC authentication user and password. Returns the response as a string. Do not use this function if the GET response type is anything but a string or null. |
invokeEndpoint | String (endpoint),Map<String,String> (metadata),String (data) | String | Invokes any MIF endpoint with the given name and metadata and string data. The response is a string. |
invokeEndpoint | String (endpoint),Map<String,String> (metadata),byte[] (data) | byte[] | Invokes any MIF endpoint with the given name and metadata and byte[] data. The response is a byte[]. |
invokeChannel | String (channel name) | void | Invokes a MIF Invokechannel with the given name. This function uses the mbo
in the context of the script and that mbo is used as the channel MBO. |
raiseSkipTransaction | NA | void | Throws the MXException with group “iface” and key “SKIP_TRANSACTION”. Used by the MIF to skip processing of certain inbound and outbound messages. |
Function | Request | Response | Description |
---|---|---|---|
log | String (log message) | void | Logs the message at DEBUG or INFO based on the setting on that script. A sample usage is as
follows: service.log("setting the replacementcost..") |
log_debug | String (logMsg) | void | Script logger logging at DEBUG |
log_debug | String (logMsg), Throwable (error) | void | Script logger logging at DEBUG |
log_info | String (logMsg) | void | Script logger logging at INFO |
log_info | String (logMsg), Throwable (error) | void | Script logger logging at INFO |
log_warn | String (logMsg) | void | Script logger logging at WARN |
log_warn | String (logMsg), Throwable (error) | void | Script logger logging at WARN |
log_error | String (logMsg) | void | Script logger logging at ERROR |
log_error | String (logMsg), Throwable (error) | void | Script logger logging at ERROR |
log_fatal | String (logMsg) | void | Script logger logging at FATAL |
log_fatal | String (logMsg), Throwable (error) | void | Script logger logging at FATAL |
Function | Request | Response | Description |
---|---|---|---|
error | String (group), String (key) | void | Throws MXException with the error group and key input parameters. |
error | String (group), String (key), String[] (params) | void | Throws MXException with the error group and key input parameters |
setWarning | String (group), String (key), String[] (params) | void | Sets warning to the mboset in context mbo.getThisMboSet() . This function is
used by REST APIs and the framework for applications that are not Graphite-based to show
warnings. |
Function | Request | Response | Description |
---|---|---|---|
yncerror | String (group), String (key) | void | Throws MXApplicationYesNoCancelException with the error group and key input parameters. |
yncerror | String (group), String (key), String[] (params) | void | Throws MXApplicationYesNoCancelException with the error group and key input parameters |
yncuserinput | String (group), String (key), String[] (params) | int | Provides the script code the input option, yes/no/cancel and so on, chosen by the user. This function is used by the script code to provide business logic for the specific input. |
Function | Request | Response | Description |
---|---|---|---|
invokeScript | String (script name), Map<String,String> context | void | Invokes a script with the given name and passes in the context that is specified in input. |
invokeScript | String (script name) | Map<String,Object> | Invokes a script with the given name. Returns the context of the invoked script as a Java™ map object. |
invokeScript | String (script name), String (function name), Object[] (function arguments) | Object | Invokes a function inside the target script with the specified arguments. The call returns the response of the function call, if any, as an object. |