The rules here come from IBM’s documentation and from our own work with the REST API, on Manage in
the MAS 9.2 series. We ran every request on our test system, against IBM’s demo data, as a user
without administrator rights. The examples read the object structure MXAPIASSET.
Why a saved query#
A saved query keeps the filter in Manage, in one place:
- The list matches the application. A mobile list or a report that runs
ACTIVEANDNEWASSETSshows the same records as the query of that name in the application. - The filter can change without a new client. An administrator edits the clause in Manage, and every client gets the new list on its next request.
- The clause can use the user’s data. A query can filter by the user’s default site or person, so one request gives each user their own list.
Find the queries: apimeta#
GET /api/apimeta/<object structure> describes an object structure. Its queryCapability array
lists every saved query the user may run on it:
GET /maximo/api/apimeta/mxapiasset{
"osName": "MXAPIASSET",
"authApp": "…",
"defaultPageSize": 100,
"queryCapability": [
{
"name": "All",
"title": "Select all",
"ispublic": true,
"href": "…/api/os/mxapiasset"
},
{
"name": "ACTIVEANDNEWASSETS",
"title": "Get list of ACTIVE and New Assets",
"ispublic": true,
"owner": "…",
"default": false,
"href": "…/api/os/mxapiasset?savedQuery=ACTIVEANDNEWASSETS"
},
{
"name": "lookupAsset",
"title": "lookup Asset",
"hasParams": true,
"javaMethod": true,
"href": "…?savedQuery=lookupAsset&sqp:siteid={siteid}"
}
]
}The first entry is always All, the list without a filter. Each other entry carries:
| Property | What it means |
|---|---|
name | the value for savedQuery, written exactly like this |
title | the description, good for a menu in your client |
href | the ready request, with a placeholder for each parameter |
ispublic, owner | a public query, or a query of its owner only |
hasParams | the query takes parameters, passed as sqp:<name> |
javaMethod | the query is a method in Java code, see below |
The list depends on the user. It holds the public queries, the user’s own queries, and the queries
of the application the object structure is bound to for security, the authApp. A public query
can also be limited to the members of a role.
The kinds of saved queries#
A name in the list can come from four places:
| Kind | Where it is defined | Name in the list |
|---|---|---|
| Application query | a saved query of an application, for example Assets | ACTIVEANDNEWASSETS, or RELENGINEER:LOWHEALTH for another application |
| Object structure query | the Query Definition action of the Object Structures application | its own name |
| Query method | a method in Java code, part of Manage or of a customization | lookupAsset, with javaMethod: true |
| Script query | an automation script registered as a query | its own name |
The queries of the application in authApp appear with their plain name. Queries of other
applications carry the application in front, such as RELENGINEER:LOWHEALTH. Those appear when
the object structure is set to load the queries of all applications.
Run a saved query: savedQuery#
Pass the name in savedQuery:
savedQuery=ACTIVEANDNEWASSETS
oslc.select=assetnum,status,siteid
oslc.orderBy=+assetnum
oslc.pageSize=20The rest of the request works as always. oslc.select, oslc.orderBy, paging, count=1 and
group by all apply to the records the query returns.
Two details cost time when they go wrong:
- The parameter name is case-sensitive.
savedquery=ACTIVEANDNEWASSETSis ignored without a word, and the request returns every record. WritesavedQuerywith the capital Q. - The query name is case-sensitive too.
savedQuery=activeandnewassetsis refused with BMXAA8741E, “The activeandnewassets query name was not found”. Copy the name fromapimeta.
A name with an application prefix contains a colon. Encode it as %3A in a URL you build by hand,
as the href in apimeta does: savedQuery=RELENGINEER%3ALOWHEALTH.
The saved query and oslc.where#
The saved query and oslc.where are joined with AND. The where clause narrows the saved query,
and it can never widen it:
On our test system, ACTIVEANDNEWASSETS returned only assets of the user’s default site, though
its title says nothing about a site. With oslc.where=siteid="TEXAS" added, it returned no record
at all. So check what a query really returns before you build on it. count=1 with and without
the saved query shows it in two requests.
Parameters: sqp:#
A query with hasParams: true takes its parameters as sqp:<name>. The href in apimeta
names them in braces:
savedQuery=lookupAsset
sqp:siteid=BEDFORD
oslc.select=assetnum,siteidA missing parameter makes the query fail. lookupAsset without sqp:siteid is refused with
BMXAA9246E, “The query method could not be invoked”. The message points at the log, and the cause
is only the missing parameter.
A KPI as the filter#
savedQuery=kpi:<KPI name> takes the where clause of a KPI from the KPI Manager. Three rules:
- The prefix is lower case.
kpi:works.KPI:is read as the application KPI, and the request fails with BMXAA8741E, “query name was not found for KPI application”. - The KPI is missing from
apimeta. You need its name from the KPI Manager. - Its where clause must fit the main object of the object structure. A clause written for
work orders fails on
MXAPIASSET.
An unknown KPI is refused with BMXAA9686E, “The KPI … is not found or its where clause field may be empty”.
A search box: oslc.searchTerms#
oslc.searchTerms searches for text in a set of attributes, the way the search field of a list
does. searchAttributes names the attributes:
oslc.where=siteid="BEDFORD"
searchAttributes=assetnum,description
oslc.searchTerms=pump
oslc.select=assetnum,description{
"member": [
{
"assetnum": "11430",
"description": "Centrifugal Pump 100GPM/60FT HD"
},
{
"assetnum": "11450",
"description": "Centrifugal Pump 100GPM/60FTHD"
}
]
}A record matches when the text appears in one of the attributes, anywhere and in any case:
PuMp finds the same records as pump.
Name the attributes in every request. Without searchAttributes, Manage takes the search
attributes defined on the object structure. On our test system, MXAPIASSET,
MXAPIWODETAIL, MXAPILOCATIONS and MXAPIPERSON had none, and every search was refused with
BMXAA8763E, “There are no search attributes defined”. searchAttributes in the request settles
it on any system. An unknown attribute there is refused with BMXAA9562E.
Several words#
The text is split at the spaces, and a record matches when it contains any of the words:
oslc.searchTerms | A record matches when |
|---|---|
pump | one attribute contains “pump” |
pump motor | one attribute contains “pump”, or one contains “motor” |
"centrifugal pump" | the same as without quotes: “centrifugal” or “pump” |
""centrifugal pump"" | the attribute contains both words |
One pair of double quotes changes nothing. Two pairs keep the words together, and then a record
needs all of them. On our test system the order of the words did not matter there:
""pump centrifugal"" found the same records as ""centrifugal pump"".
Two more results from our test system:
- A search term with a slash, such as
100GPM/60FT, found nothing, though that text is in a description. Search for the parts,100GPM. - A
%in a search term found nothing. The search already matches anywhere in the text, so leave wildcards out.
oslc.searchTerm, singular, is ignored without an error, and the request returns every record. The
parameter is oslc.searchTerms.
Search inside a saved query#
Search terms work together with a saved query. This gives a search box over the user’s list:
savedQuery=ACTIVEANDNEWASSETS
searchAttributes=description
oslc.searchTerms=pump
oslc.pageSize=20Query templates#
A query template stores the rest of a request in Manage: the page size, the attributes to select
and their order, and the search attributes. It is a record of the object structure
MXAPIQUERYTEMPLATE, and querytemplate=<name> applies it. A template applies only to the object
structure it was made for, and a template for another one is ignored without an error. Anything
the request sets itself wins over the template. IBM’s
saved query page shows how
to create one.
Errors at a glance#
| Request | Answer | Fix |
|---|---|---|
savedquery=…, small q | 200, every record | write savedQuery |
savedQuery= with a wrong name or case | 400 BMXAA8741E | copy the name from apimeta |
a query with hasParams, parameter missing | 400 BMXAA9246E | add sqp:<name>=<value> |
savedQuery=KPI:… | 400 BMXAA8741E | write kpi: in lower case |
savedQuery=kpi: with an unknown KPI | 400 BMXAA9686E | check the name in the KPI Manager |
oslc.searchTerms without search attributes | 400 BMXAA8763E | add searchAttributes |
searchAttributes with an unknown name | 400 BMXAA9562E | use an attribute of the main object |
oslc.searchTerm, singular | 200, every record | write oslc.searchTerms |
Examples#
Each request below returned data on our test system. Each line is one query parameter.
A saved query of another application, as a count:
savedQuery=RELENGINEER:MISSINGINSTALLDATE
oslc.where=siteid="BEDFORD"
count=1A saved query, counted per status:
savedQuery=ACTIVEANDNEWASSETS
gbcols=status,count.*A search over the work orders:
/api/os/mxapiwodetail
oslc.where=siteid="BEDFORD"
searchAttributes=description
oslc.searchTerms=pump
oslc.select=wonum,description,status
oslc.pageSize=20All words must match:
oslc.where=siteid="BEDFORD"
searchAttributes=description
oslc.searchTerms=""centrifugal pump""
oslc.select=assetnum,descriptionWhat comes next#
IBM’s own pages are the reference to keep next to this article:
- Saved queries in the IBM Maximo Manage documentation.
- Query (GET) / Saved query in IBM’s Maximo REST API guide on GitHub.
The next article of the series covers domain values in a query. The series overview lists all parts. If you want help with the REST API in your own Manage, our services page shows how we work, or get in touch.
IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.
