
Updating End Points and Reloading Cache in Automation Script
- November 7, 2019
- Kelly
- 3 Responses
- November 7, 2019
- Kelly
- 3 Responses
In Maximo you can use End Points to point to External APIs to pull in data. You can invoke those End Points in a variety of ways, including inside an Automation Script. Take the following code as an example:
handler = Router.getHandler('ENDPOINTNAME');
responseBytes = handler.invoke(null, null);
You can then parse the response that comes back and use that data in any way that meets your needs. Recently we were working with an external API that required an initial login to capture an API Key to be used with future calls. We called the Login API and then grabbed an API Key from the response object. We then needed to update a different End Point to utilize this API Key as an HTTP Header in future calls.
This appeared to work in Maximo as we would see the data show up on the updated End Point. However, each time we invoked the End Point it would throw an error that it was not able to connect. We would then restart Maximo and everything would start working. What we found is that End Point data in Maximo is cached. After updating an End Point, we needed to reload the End Point cache to make a successful connection. To do that we added a line in the automation script after we updated and saved the End Point with the new API Key. The line that is needed is:
MXServer.getMXServer().reloadMaximoCache(EndPointCache.getInstance().getName(), true);
After running this code we can now successfully call our updated End Point. Be aware that there are several similar objects that are cached when Maximo starts up, such as Relationships, Integration information, some Domain information, etc. If updates are made to those records, you may need to refresh the Maximo cache for those records as well.
Hope this helps!
3 Comments
Hi, I know that this question isn’t related, but I would appreciate some help.
I need to run script or java code on opening record. For example script named ASSET.NEW fires on creating new record, but there is no ASSET.OPEN or something like that.
As for Java I didn’t find any method that triggers on opening existing record. Every method i override ends up changing every record on list – for example void init(), valueChanged(), modify()…
Is there any way to achieve this?
Thank you. Regards
Unfortunately, there’s no event available that I know of that hooks into the opening of a record like that. The initialize event runs each time a record is loaded into a set, which typically first happens on the List View tab.
You can accomplish this by creating a new persistent MBO(I’ll call it SCRIPTTRIGGER), then creating a single record of that object. Then create a relationship from ASSET to SCRIPTTRIGGER, and use a hidden textbox in your Asset App to trigger that relationship to load & the ScriptTrigger object to fire an init script. From the init script, you can get a reference to the owning Asset using getOwner() and perform any logic you need.
Hope that helps!