MBR Automation Scripts : The Less Treaded Path

Introduction:

MBR scripts which expands to Maximo Business Rules, are a different approach that you can use to customise and enhance your Maximo applications. You can write them in a language that is similar to Python, but with some special features and functions that are specific to Maximo.

Use Case:

For example, you can use MBR scripts to:

  • Create custom actions or buttons that perform certain tasks or calculations

  • Validate or modify the data that users enter or change in the applications

  • Add or remove MBOs (Maximo business objects) from an MBOSet (a collection of MBOs)

  • Call other scripts or libraries that contain reusable code

  • And much more!

Automation Script > Create Script > Script Language > MBR











MBR is a language that is designed for Maximo products, while Python is a general-purpose language that can be used for various applications. Here are some of the advantages and disadvantages of MBR :

  • MBR has the advantage of being compatible with the Multi tenant environment of Maximo, and being able to access and manipulate the Maximo data model directly.

  • MBR also has some built-in functions that are specific to Maximo, such as newmbo,  getvaluefrommbo, setvaluetombo, and sendemail.

  • There is no need to import additional libraries to run the MBR script. 

  • Codes can be simplified and we don’t need to worry about memory leakages.
  • MBR has the disadvantage of being not as widely used or supported as Python, and having some limitations, such as not supporting loops, arrays, or dictionaries. 
  • MBR also can be more expensive to set up and run than Python.

Sample Code:

Find below an example on how to write an automation script using MBR :

#MBR code to calculate the total cost of a work order
#Get the labor, material, service, and tool costs from the work order
setvar ("laborcost", getvaluefrommbo ("actlabcost"))
setvar ("materialcost", getvaluefrommbo ("actmatcost"))
setvar ("servicecost", getvaluefrommbo ("actservcost"))
setvar ("toolcost", getvaluefrommbo ("acttoolcost"))

#Add the costs to get the total cost
setvar ("totalcost", (getvar ("laborcost") + getvar ("materialcost") + getvar ("servicecost") + getvar ("toolcost")))

#Update the total cost attribute of the work order
setvaluetombo ("totalcost", getvar ("totalcost"))

Functions frequently used in MBR:

  • getvaluefrommbo: This function returns the value of an attribute from an MBO (Maximo business object).
  • setvaluetombo: This function sets the value of an attribute to an MBO.
  • getvar: This function returns the value of a local variable that is created by using the setvar function.
  • setvar: This function creates and assigns a value to a local variable.
  • getmboset: This function returns an MBOSet that matches a given query.
  • countf: This function returns the number of MBOs in an MBOSet.
  • newmbo: This function creates a new MBO and adds it to an MBOSet.
  • sendemail: This function sends an email to a specified recipient with a given subject and body.
  • random: This function returns a random number between a given range.
  • getcurrentdate: This function returns the current date and time.
  • adddays: This function adds a number of days to a date and returns the new date.
  • invokescript: This function calls another script or a library script from the current script.

Send an Email:

One of the best use case of MBR Script is to send out a simple e-mail. You can use the sendemail()function in MBR script to send an email to a specified recipient with a given subject and body. 

The syntax of the sendemail function is:

sendemail (recipient, subject, body)

where:

  • recipient is a string that contains the email address of the recipient
  • subject is a string that contains the subject of the email
  • body is a string that contains the body of the email

For example, you can use the following MBR code to send an email to “user@domain.com” with the subject “Hello” and the body “ Transaction successful”:

sendemail (“example@example.com”, “Hello”, “Transaction successful”)

For example, you can use the following MBR code to send an email to the owner of a work order with the subject “Work order completed” and the body “The work order has been completed successfully”:

#Get the owner of the work order and set the values for variables
setvar (“owner”, getvaluefrommbo (“owner”))
setvar (“subject”, “Work order completed”)
setvar (“body”, “The work order has been completed successfully”)
#Send the email to the owner 
sendemail (getvar (“owner”), getvar (“subject”), getvar (“body”))

Reference


Comments

  1. Very nice Article. Python code for Maximo. This is revolutionary.

    ReplyDelete
  2. This is informative. I have a question though, is this sendemail function read the TOLIST attribute defined in commtemplate and send the email?

    ReplyDelete
    Replies
    1. The sendemail() function is quite simple, it just sends out an email to the specified used, with the body and content which we specify in the parameters

      Delete

Post a Comment

Popular Posts