Showing posts with label mbo. Show all posts
Showing posts with label mbo. Show all posts

Monday, 8 March 2021

Maximo Date Manipulation Using Automation Scripts

In this topic, we are going to see how to manipulate Maximo dates using Automation scripts. The different kinds of manipulation are

  1. Adding Number to the date
  2. Subtracting Number to the date
  3. Changing the format of the date
  4. Difference between two dates in days 

In the below examples we are going to use Python scripts in Maximo

  1. Object Launch Point is used
  2. Asset object
  3. The “INSTALLDATE” attribute is modified

  Java Calendar class is used for Date Manipulation.


1.     Adding Number to the date

Current date from MXServer is got and adding number (10) to that date.

print("**************Start of C_TEST ********************")
from java.util import Date
from java.util import Calendar
from psdi.server import MXServer

currentDate = MXServer.getMXServer().getDate()
cal = Calendar.getInstance()
cal.setTime(currentDate)

cal.add(Calendar.DATE, 10) 

print ("After Additional to Current Date ---> ",cal.getTime()) 

mbo.setValue("INSTALLDATE",cal.getTime()) 
print("**************End of C_TEST ********************")

Tuesday, 13 August 2019

Populating Condition Codes By Just Clicking Condition Code Check Box in Maximo

Recently we had a requirement to add the condition Code on clicking the Condition Code Check box in Item application.

Below is the Code that was written in JavaScript,
Launch Point Type: Attribute Launch Point
Object: Item
Attribute Name: CONDITIONENABLED

importPackage(Packages.psdi.mbo);

var conditioncode  = mbo.getBoolean("CONDITIONENABLED");
var itemconditionSet = mbo.getMboSet("ITEMCONDITION");

if(conditioncode)
{
  for(i=0;i<3;i++)
  {
    var itemcondition = itemconditionSet.addAtEnd();
    if(i == 0)
    {
      itemcondition.setValue("CONDITIONCODE","A");
    }
    else if(i == 1)
    {
      itemcondition.setValue("CONDITIONCODE","B");
    }
    else if(i == 2)
    {
      itemcondition.setValue("CONDITIONCODE","C");
    }
  }
}



Wednesday, 24 July 2019

Maximo Automation Script setting values while Initializing

There are times where we need to set the value when the object is invoked rather that setting the values during the save method. This can be achieved in Maximo automation scripts.

Step 1: Create an Object Launch Point with JavaScript.
Step 2: Make sure to check the Initialize? check box is checked. And all other check box are unchecked.
Step 3: Below is the sample code for setting the "Inspection Required" and "Adding Spare Parts" check box to always be checked when the item is created.

importPackage(Packages.psdi.mbo);
if(mbo.getString("ITEMSETID")=="ITEMSET1"){
    if(mbo.toBeAdded()==true){
        mbo.setValue("INSPECTIONREQUIRED", 1);
        mbo.setValue("SPAREPARTAUTOADD", 1);
    }
}

Tuesday, 10 April 2018

Python - setting Date and Time using automation Scripts

The python version used Maximo automation scripts is 2.5.2. So the normal DateTime function in Python cannot be used in Maximo. The DateTime function is used in Python 3.x and above. As an alternative, we can use the gmtime and strftime packages.

from time import gmtime
from time import strftime
nowTime = strftime("%Y-%m-%dT%H:%M:%S", gmtime())
print(nowTime)
mbo.setValue("TARGSTARTDATE", nowTime)
print("TARGSTARTDATE-->" + mbo.getString("TARGSTARTDATE"))