Role automation scripts

Roles play an important part in workflow and communication templates. Roles often resolve to a specific person or email based on data in the record, such as the supervisor on the work order. In those cases, this functionality is not needed.

Use this functionality when the scenario becomes more complicated, such as if you want to check the person’s supervisor hierarchy until you get to someone with sufficient approval limits that can approve the PO. When you need to return only a single value, you could create a nonpersistent attribute and populate that attribute by using an attribute launch point. However, that requires an outage for the database configuration and does not support returning more than a single value. The role automation script is useful in this situation.

To create a role-based automation script, create a role with custom class type and the value as com.ibm.tivoli.maximo.script.ScriptCustomRole.

The name of the role, for example EMXROLE, is used in defining the automation script. The script is created without a launch point in the name format MAXROLE.ROLENAME.

Note: Ensure that you enable the ability to invoke script functions. This ability is disabled by default and the script does not run without this ability. You cannot change this setting after the script is created.

There are two functions that you can declare in your script that will be invoked. You can declare evalToEmail or evalToPerson functions. These functions are passed as a variable that exposes the methods from the ScriptRoleContext. ScriptRoleContext extends ScriptService so all of those methods are available as well.

The following table shows the public methods available in ScriptRoleContext.
Table 1.
Method name Parameters (Type) Description
getMaxRole None Returns the MAXROLE MBO. This class exposes a variety of methods that can be used such as getPerson(personid) to get a person MBO.
addEmailId Email (String) Adds a new email address to the array to be sent.
getEmailIds None Returns the string array of the emails that have been added.
setPersonOrGroupMbo Mbo (Mbo) Sets either a Person MBO or PersonGroup MBO.
getPersonOrGroupMbo None Returns the Person or PersonGroup MBO that has been set.
getMbo None Returns the MBO record for resolving.
The following example script sets persongroup to TIER1 or TIER2 depending on the SITEID.
def evalToPerson(ctx):
    # This method comes from the ScriptService 
    mbo=ctx.getMbo()

    personGroup=None
    if mbo.getString("SITEID")=="BEDFORD":
        personSet=mbo.getMboSet("$EMXPERSONGROUP","PERSONGROUP","persongroup='TIER1'")
        personGroup=personSet.moveFirst()
    else:
        personSet=mbo.getMboSet("$EMXPERSONGROUP","PERSONGROUP","persongroup='TIER2'")
        personGroup=personSet.moveFirst()

    # This comes from the ScriptRoleContext
    ctx.setPersonOrGroupMbo(personGroup)