Thursday, August 21, 2014

Maximo Automation Script to concatenate two fields in one.

Goal:
To create an automation script in Maximo 7.5.0.5 that conbines two fields into a new field and is triggered by the change of one of the fields.


Example:
I have two fields in my application and want to combine those fields into one new field. 

One field on the record contains a project number and the other field contains a number unique for that project. The unique identifier for the record should be the project number + number.


Solution:

The concatenated number will be stored as my IssueID.

I created three fields in Database Configuration
  • Number used for IssueID  (GMBISSNUM - INTEGER 12)
    • This is a number that increases and will only be unique per Project.
  • Issue ID (GMBISSUEID - UPPER - 20)
    • This will be the concatenated ID (Project + Number)
  • Project (GMBPROJECT - UPPER - 10)
    • A workorder number.
I have put the fields on screen like you can see below:


Next I create the Script. Go to the Automation Script application and choose in the Select Action menu for Cerate -> Script with Attribute Launch Point


In the first step, fill in a name for 'Launch Point', a 'Description', check if the 'Active?' checkbox is set, I choose 'SR' as the Object and want the script to run if the Attribute 'GMBPROJECT' is changed.


Click [Next] to go to step 2

In step 2 fill in a Name for the Script, a Description, check if the Script Language is set to 'jython'.


Click [Next]  to go to the next step.

Here we will put the following script in the 'Source Code' field:

import java;
import sys;
from psdi.mbo import Mbo;
from psdi.mbo import MboSet;
from psdi.server import MXServer;

myMxServer = MXServer.getMXServer();

#mbo is the current mbo from where the script is run.

myProjectIssueSet = myMxServer.getMboSet("SR", myMxServer.getSystemUserInfo())
wherestring = "gmbproject = '" + mbo.getString("GMBPROJECT") +"'"
myProjectIssueSet.setWhere(wherestring);
myProjectIssueSet.reset();

count = myProjectIssueSet.count();

#Determine if there is a number for the project.
if count > 0:
  #there are records, so there are numbers. Put them in an array
  issueNumbers = [];
  for i in range(count):
    myProjectIssue = myProjectIssueSet.getMbo(i);
    issueNumbers.append(myProjectIssue.getString("GMBISSNUM"));
    i += 1;

  #take the highest number from the array and increase it by one.
  highNumber = max(issueNumbers);
  highNumber2 = int(highNumber) + 1;
  GMBISSNUM = str(highNumber2);

  
#There is no existing number for this project.  
else:
  #this is the first issue for this project. So start with number 1
  GMBISSNUM = '1';

#Generate the IssueID from the Projectnumber and the Issuenumber for the selected project.  
GMBISSUEID = str(GMBPROJECT) + "_" + str(GMBISSNUM);


myProjectIssueSet.close();


Click [Create]  to create the launch point and script.

The following message will pop-up (BMXAA7989I - The launch point was created successfully.)


Click [Close]

In the List the created script appears, click on it to open it and go to the 'Variables' tab. We need to create three variables here:

Variable:            GMBISSNUM
Variable Type:   INOUT
Override?:          checked
Binding Type:    ATTRIBUTE


Variable:            GMBISSUEID
Variable Type:   OUT
Override?:          checked
Binding Type:    ATTRIBUTE


Variable:            GMBPROJECT
Variable Type:   IN
Override?:          checked
Binding Type:    ATTRIBUTE


Click the 'Save' Icon in the top to save out work.

Next go to the Launch Points tab and click on 'Edit Launch Point Detail' icon in front of the Launch Point name.


Fill in the 'Binding Variables' for the variables on the Launchpoint. This will link the variable used in the script to the attribute in the Maximo database.


Click [OK] and Save the Script.

We go to the Application and create a new record.
Now when we fill in the 'Project' field the Number used for IssueID and the Issue ID fields are filled in by the script.


In this example the 'Number used for IssueID' is unique per Project. So the number 4 will only appear once for project 1002. It can however appear again for project 1003. This logic is also done in the script.


GNZ.