<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1066880148/?value=0&amp;label=4oTQCMyJzwQQlJnd_AM&amp;guid=ON&amp;script=0">
Jeff Kish

By: Jeff Kish on July 30th, 2020

Print/Save as PDF

Automation Script pseudo-code Instruction

Maximo Tech Post | Automation Script

Automation script pseudo-code instruction.

I first ran across this about forty years ago when working in a Fortran environment. My team was working on a military contract and to meet a documentation requirement, we were told to use a template for our Fortan code to allow automatic extraction of comments to supply to the customer as part of a way to meet the mil-std 1679 project requirements. One of the gurus there developed the process and program(s) required to do the work and the rest was, in a sense, history.

Imagine my recent surprise when at the 11th hour, my customer insisted on interpreting our requirements as meaning we supply pseudo-code for all of our (hundreds) of javascript automation scripts we had developed for them – separately from the scripts themselves. I knew that there was some variability in the commenting in the automation scripts, however if I could extract comments and certain statements such as 'service.log' statements and put them in a file for each script it would be a great start.

My approach was to tie a button on a screen to an action and automation script. The vision was that I would use the MIF to load all the launchpoints and automation scripts into my local VM, and then click the button to write all the pseudo-code files for all automation scripts (written in javascript) to a subdirectory under the folder identified by 'mxe.int.globaldir'. I decided to put it in a subfolder named 'js'. I realized I didn't have the resources to develop a lexer, and I couldn’t find one to use for javascript, so I settled on the following:

  • Extract all block comments (starting with /* or ending with */
  • Extract all single line comments (starting with //)
  • Extract all logging statements of interest (starting with service.log)

Caveats

  • I just had simple requirements to get most of the way there.
  • Comments that are not 'well formed', i.e. are on the same line as code are not processed very well or at all
  • There may be other situations also – try it out to see if it fits your needs.
  • I created the target directory manually in advance because I had issues creating directories.
  • The files produced overwrite existing files of the same name and location.
  • You can replace service.log with whatever you want. We used this because they output logging when the Maximo autoscript logger is set to 'info' or 'debug'.

 

Note that I created a table to use as the launchpoint named AUTOCOMMENT because I wanted a launchpoint to refer to a button on the autoscript screen but you can't specify that internal table for a launchpoint. This is basically a placeholder that has only a couple of persistent fields to tie it to the autoscript table. A pair of non persistent fields were used for some troubleshooting and alternate processing I explored while assembling this. Here is a dbc for this object and also the setup for its creation:

1 - Automation Script pseudo-code Instruction

 

2 - Automation Script pseudo-code Instruction

AUTOCOMMENTDO.DBC

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script SYSTEM "script.dtd">
<script author="jkish" scriptname="autocommentdo.dbc">
          <description>DROP IF existing THEN CREATE autocomment table</description
          <statements>
                   <drop_relationship name="AUTOCOMMENT" parent="AUTOSCRIPT" />
                   <drop_table object='AUTOCOMMENT'/>
                   <define_table persistent="true" type="system" object="AUTOCOMMENT"

description="AUTOSCRIPT COMMENTS" service="CUSTAPP" classname="psdi.mbo.custapp.CustomMboSet" mainobject="false" internal="false">
                             <attrdef attribute="AUTOCOMMENTID" maxtype="BIGINT" title="Autocommentid" remarks="Autocommentid"  length="19" persistent="true" required="true" mustbe="true" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="EXACT" localizable="false" restricted="false" />
                            <attrdef attribute="AUTOSCRIPT" maxtype="UPPER" title="Autoscript" remarks="Autoscript"  sameasobject="AUTOSCRIPT" sameasattribute="AUTOSCRIPT" length="100" persistent="true" required="false" mustbe="true" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="WILDCARD" localizable="false" restricted="false" />
                          <attrdef attribute="DESCRIPTION" maxtype="ALN" title="Description" remarks="Description"  length="50" persistent="true" required="false" mustbe="false" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="WILDCARD" localizable="false" restricted="false" />
                         <attrdef attribute="SCRIPTLANGUAGE" maxtype="ALN" title="Scriptlanguage" remarks="Scriptlanguage"  sameasobject="AUTOSCRIPT" sameasattribute="SCRIPTLANGUAGE" length="50" persistent="true" required="false" mustbe="false" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="WILDCARD" localizable="false" restricted="false" />
                        <attrdef attribute="SOURCEALN" maxtype="ALN" title="Sourcealn" remarks="Sourcealn"  length="4000" persistent="false" required="false" mustbe="false" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="NONE" localizable="false" restricted="false" />
                        <attrdef attribute="SOURCECLOB" maxtype="CLOB" title="Sourceclob" remarks="Sourceclob"  sameasobject="AUTOSCRIPT" sameasattribute="SOURCE" length="999999" persistent="false" required="false" mustbe="false" ispositive="false" canautonum="false" userdefined="true" haslongdesc="false" defaultvalue="" scale="0" searchtype="NONE" localizable="false" restricted="false" />
              </define_table>
              <modify_table name="AUTOCOMMENT" primarykey="AUTOSCRIPT" />
              <create_relationship name="AUTOCOMMENT" parent="AUTOSCRIPT" child="AUTOCOMMENT"
whereclause="autoscript = :autoscript" remarks="one to one mapping from AUTOSCRIPT to AUTOCOMMENT" />
          </statements>
</script>

EXECUTE SCRIPT FROM COMMAND LINE:

[maximo@maximo76vm internal]$ pwd
/opt/IBM/SMP/maximo/tools/maximo/internal
[maximo@maximo76vm internal]$sudo ./runscriptfile.sh -cnps -fautocommentdo
Log file: MAXIMO_RUNSCRIPT_autocommentdo.log
RunScript complete: Successful
Checking for columns missing from E-Audit tables.
Found no columns missing.
[maximo@maximo76vm internal]$

I developed and ran this on this system:

3 - Automation Script pseudo-code Instruction

So I did all this on my VM, exporting the automation script information from my customers system to mine so I could work there. I added a button to the automation script application screen but you could add it anywhere.

Steps:

  1. Create a button and tie it to an action that a script could activate

This has been done by many people already – I like this other blog and used their method:

http://sometimesiliketopretend.blogspot.com/2013/08/maximo-75-use-button-with-automation.html

In case the link fails in the future, here is a quick overview:

  • Add an automation script with Action Launch Point. The names will be the same as the button event. Mine was 'AUTOCOMMENTDO'
    • Javascript is the language to use
    • Saving this means the system behind the scenes creates an action of the same name.
    • Since I had no script yet I put a boilerplate in the source for now.
  • Verify the action was created in the Administration | Actions application
  • Use app designer to add the sigoption of the same name as the button event and automation script.
    • Under advanced indicate this is an action that must be invoked by the user in the UI
    • Add a push button and make sure the event it the same as the name of the action and automation script
  • Use Security Groups to give maxadmin (or some other group you use) rights to the new action (grant access checkbox).
  • Now go back and put the code in the script. Make sure you log out and back in so the security rights are updated and you can use the button.
4 - Automation Script pseudo-code Instruction

Here is the automation script:

5 - Automation Script pseudo-code Instruction

Follow up notes.

In order to move the script exports between the customers system and my vm I used migration manager to create a package to move an external system named 'CONFIG' that was setup to allow this. Note that you need to activate the external system and associate it with your queues on your system before you can import or export launchpoints or scripts. This has been very handy for me.

About Jeff Kish

Jeff is a Senior Technical Consultant at Interloc Solutions and has worked with Maximo since 1999. Jeff has worked with PSDI/MRO/IBM for three years as a developer and has worked as a consultant on multiple projects since April 2009.