Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Get a value from MAXVARS using automation script

    Posted Thu October 07, 2021 12:35 AM
    MAM 7.6.1.2:

    I want to select a specific value from the MAXVARS table.
    The SQL equivalent would be: select varvalue from maxvars where varname = 'MAXIMO_ENV'
    Result: DEV

    Is there a way to do that with a Java method in an automation script? (not with SQL)

    Thanks.
    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Get a value from MAXVARS using automation script

    Posted Thu October 07, 2021 02:24 AM
    Edited by System Admin Wed March 22, 2023 11:46 AM
    Considering your other post about adding new data in MAXVARS (Edit MAXVARS data via UI), I think it's worth circling back and thinking about what you're trying to achieve overall.

    If your goal is to store a custom value (say the environment ID/designation) somewhere that you currently have not found a place to store, and use that in Automation Scripts, I would rather do that as System Properties. Those can be added through the UI, and you can go through the MXServer.getProperty() method in scripts to retrieve it.

    Assuming you are using public properties:

    from psdi.server import MXServer
    publicProperty = MXServer.getMXServer().getProperty("company.public.propertyname")
    H/T: https://stackoverflow.com/questions/52280850/fetch-system-property-in-automation-script-in-maximo

    I've seen this used for storing variables that are required to change quickly between environments and across multiple automation scripts, for instance an external system URL, an external system login ID etc.
    We have some integrations that rely on automation scripts where our development environment maps to one ext. system, and the production system maps to another. By storing it in a System Property we can do changes to the scripts as needed and migrate them without worrying about any hardcoded values.

    ------------------------------
    Henrik Christiansen
    ------------------------------



  • 3.  RE: Get a value from MAXVARS using automation script

    Posted Fri October 08, 2021 02:59 AM
    Hi You can get Like this

    getMboServer().getMaxVar().getString("'MAXIMO_ENV", getOrgSiteForMaxvar("'MAXIMO_ENV"))

    ------------------------------
    Sahil Dutta
    ------------------------------



  • 4.  RE: Get a value from MAXVARS using automation script

    Posted Fri October 08, 2021 08:58 AM
    Edited by System Admin Wed March 22, 2023 11:47 AM
    If storing in system properties, you can also call service.getProperty("propname") to avoid the MXServer import in your script.

    For MAXVARs, Sahil mentioned it but it might not be clear in that context that you would call that from your MBO record. The provided syntax was for Java, but inside an automation script it'd look more like:

    mbo.getMboServer().getMaxVar().getString("'MAXIMO_ENV", mbo.getOrgSiteForMaxvar("'MAXIMO_ENV"))


    In both scenarios, there's an important concept to be understood. Both of these are cached which means that if changes occur to the value, there will be a small delay (~1 minute) before other JVMs pick up the value. A query would be real-time. The advantage to the cache is it'll obviously be faster than reading from the database but if you're using it for something that changes often (such as credentials for an integration) you could hit issues. When I built integrations for OAuth for example I'd update the access token 5 minutes before it expired so that it'd have time to propagate across the JVMs. 


    ------------------------------
    Steven Shull
    ------------------------------



  • 5.  RE: Get a value from MAXVARS using automation script

    Posted Fri October 08, 2021 11:14 AM
    A slightly different way to get MAXVARS value from the MaxVarService directly so you don't need a reference to an mbo.

    ((MaxVarServiceRemote)MXServer.getMXServer().lookup("MAXVARS")).getString("VARNAME", "ORG/SITE");
    Same MaxVarServiceRemote object in both cases, but a little more explicit in my opinion.

    ------------------------------
    Jason VenHuizen
    ------------------------------