Examples of Maximo Business Rules (MBR) scripts
Several examples are provided to illustrate how to use Maximo® Business Rules (MBR) language in several common scripting scenarios.
Example: Adding an MBO to an MBOSet
When a new asset is added with an asset type of GASENG, the record adds two meters to the meter MBOSet of the asset. The meters are O-PRESSUR and IN-PRESSUR.
- In the Automation Scripts application, create a script that has an object launch point.
- Specify the launchpoint name and select the ASSET object.
- In the Events section, select the Save event.
- In the Save section, specify the context for the event and select Add and Before Save.
- In the Script section, select the option to add a script and advance to the next page.
- Specify a script name and set the log level to debug. Advance to the next page.
- Paste the source code that follows into the Source Code field and click
Create to add the script.
#my first MBR code for asset setvar("isgaseng",(assettype == "GASENG" && countf("assetmeter")==0)) if(getvar("isgaseng"),invokescript(":createmeters")) #my MBR function that will add the two meter MBOs to the asset MBO :createmeters newmbo("opressure","assetmeter") setvaluetombo("opressure","metername","O-PRESSUR") newmbo("inpressure","assetmeter") setvaluetombo("inpressure","metername","IN-PRESSUR")
Analysis
This script contains two lines of main code and a function. The script is run when a user saves changes to an asset record. In the main code, the following logic is implemented:
- Create a local variable and set the variable to
TRUE
if both of the following conditions are true:- The asset type is GASENG.
- The meter MBOSet of the asset is empty.
- Evaluate the local variable. If the local variable is
TRUE
, call a function to add MBOs to the meter MBOSet of the asset. In the createmeters function, the following logic is implemented:- Add an MBO to the meter MBOSet of the asset.
- Set the name of the MBO to O-PRESSUR.
- Add a second MBO to the meter MBOSet of the asset.
- Set the name of the second MBO to IN-PRESSUR.
The script uses two internal variables, assettype and assetmeter to derive the asset type and the contents of the meter MBOSet of the asset.
Because this script runs when a user saves their changes, the application transaction framework saves and commits the newly created MBOs as part of the main transaction.
You can move the createmeters function code into a library script. For example, you can move the createmeters function code to a library script that is also called createmeters and then call the library script in the following statement:
if(getvar("isgaseng"),invokescript("createmeters"))
Example: Manipulating dates
- Set the end of life date to the installation date plus one year. If the asset does not have an installation date, set the end of life date to the current date plus one year.
- Make the priority attribute mandatory.
- In the Automation Scripts application, create a script that has an attribute launch point.
- Specify the launch point name, and select the ASSET object and the ASSETTYPE attribute.
- In the Events section, select the Validate event.
- In the Script section, select the option for a new script and advance to the next page.
- Specify a script name and set the log level to debug. Advance to the next page.
- Paste the source code in the following section into the Source Code field
and click Create to add the script.
if(assettype=="BUS",setvalue("estendoflife",nvl(installdate,now())+duration(1,0,0,0,0,0))) if(assettype=="BUS",setrequired("priority",TRUE),setrequired("priority",FALSE))
Analysis
This script is run when the asset type is modified. In the script, the following logic is implemented:
- If the asset has a type of BUS, set the end of life date:
- Evaluate the installation date of the asset.
- If the installation date is empty, set the end of life date to the current date plus one year.
- If the installation date is populated, set the end of life date to the installation date plus one year.
- If the asset has a type of BUS, make the priority attribute mandatory. If the asset does not have a type of BUS, make the priority attribute optional.
if(assettype=="BUS",invokescript(":seteol"),setrequired("priority",FALSE))
:seteol
setvalue("estendoflife",nvl(installdate,now())+duration(1,0,0,0,0,0))
setrequired("priority",TRUE)
The script uses the internal variables assettype, estendoflife, and installdate to derive the values of the type, end of life date, and install date of the asset.
Example: Setting attributes on duplicate objects
When a work order is duplicated, copy the original work order number to a custom attribute in the duplicate work order.
- In the Automation Scripts application, create a script that does not have a launch point.
- Specify a script name of WORKORDER.DUPLICATE.
- Specify MBR as the script language if it is not specified.
- Paste the following source code into the Source Code field and click
Create to add the script:
setvaluetombo("dupmbo","copiedfrom", wonum)
Analysis
The script name ensures that this script runs when a work order is duplicated. The script copies the original work order number into a custom attribute in the duplicate work order.
The script uses the internal variables wonum, dupmbo, and copiedfrom to derive the values of the original work order number, the duplicate work order number, and the custom attribute on the duplicate work order.